I'm working on a program which will generate some temporary files, wait for the user's input on a few things, then use these temporary files for an operation.
I was wondering if I can reliably expect that these temporary files will not go away before I am completely done with them (e.g. will they disappear while the user is working?).
Obviously, I could create my own folder in my appdata and use that for temporary files. But it would be easier to use C#'s Path.GetTempFileName()
or Path.GetTempPath() + somename
. When would files created in this way be removed?
To clarify, I'm not looking for how to create temporary files, but rather how long temporary files created in GetTempPath()
are kept, and whether or not that would be long enough to wait for user input before using them.
You can easily delete these temporary folders to free up space on your computer. But using the Disk Cleanup tool only deletes temporary files that are older than seven days. Even the new Storage Sense feature in Windows 10 won't automatically clear temp files all the time. Why is this?
Most of the temporary files that the system uses are deleted automatically after the task is complete. But there can be some files which stay in your storage for future use. The same can apply for your daily use programs which need these temporary files to complete operations and tasks faster for the users.
After completing the steps, Windows 10 will automatically delete temporary files and those files that have been in the recycle bin for over 30 days.
The temporary file that is created when Word performs an automatic save is stored in the Temp folder, unless there is not a valid Temp folder. In this case, Word saves the temporary file in the same folder where it saves the document.
I'm not aware of any process in Windows that deletes temporary files automatically. The user may have a cleanup job set up, but you can reasonably expect your files to be left alone for a day or two as a minimum.
For comparison, when you open an attachment in Outlook, it copies the attachment to a temporary file and launches the associated application. These temporary attachment files might need to stay around indefinitely, if the user never closes the associated application.
It's completely safe, and your instinct is 100% correct--this is the way to handle temp files, as long as you remember to clean them up afterwards.
Calling GetTempPath()
does nothing more than point you to a safe place to put temporary files. It's the modern equivalent of getting the value of the environment variable PATH
. The directory is never cleared automatically -- you'll often find it filled with ancient junk.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With