when you already know the structure of your file.
[user settings] -> dosent change
moviedir= -> dosent change
imagedir= -> dosent change

so just read the entire thing... form the string in memory with new value and write back to file