Search code examples
windowstemporary-files

Windows programming application and writing temporary files


I am writing an app that may have in its memory quite a bit of data. I dont want to write the data to disk ad hoc because there may be more data to write, I could append the data, but I dont want to run into any file corruption issues.

Are there any good tutorials or trusted methods describing how a windows program typically makes use of temp files? I want to be able to recover the data on a disaster such as a reboot or loss of power.


Solution

  • Typically applications will write their temporary files to %TEMP% if they just need temporary non-recoverable file access, however, you will probably be better off writing them to the Users directory in your own folder you have created there. This folder is typically going to be the same spot that the User would choose when the Save dialog pops up. An important point is to give the files a unique naming scheme and file extension to differentiate them from user-created files (or even put them in their own hidden directory).