do files in the temporary folders get automatically deleted?

26

4

We are thinking to make our web application hosted on a windows server 2003 machine create temporary files, and "leave" it there as such. We won't manually take any action on them. So will these files get automatically deleted? Or is there some sort of policy we have to configure - like these files should get deleted after 30 days or so...

Update:

A production server will hardly get shutdown. What to do then if the files have to be deleted somehow?

deostroll

Posted 2011-08-03T12:40:56.890

Reputation: 1 515

4

Possible duplicate of When is a Windows User's Temp directory cleaned out?

– Ultralisk – 2017-01-18T09:32:02.190

Answers

18

No, there's nothing turned on by default in Windows that will automatically delete temp files. Not on shutdown, not on reboot, not ever.

The Disk Cleanup tool has an option to do that when its run.

The proper way to handle this is for your web application to clean up after itself in some way. You might have it delete orphaned files when a user logs out, for example. Or a (small) random chance that a "cleanup sweep" will be made on every request. Or a scheduled task that must be installed and configured to do cleanup. Or a scheduled task to run Disk Cleanup.

Do not go about just "leaving stuff" in the temp folder in the hopes that something will come along and clean up your mess for you.

Also, when you do go about cleaning up your files, only touch the files that you've created and no others. Other applications may need those files. If tracking your own files is too much trouble, create a folder that you can safely empty at will.

afrazier

Posted 2011-08-03T12:40:56.890

Reputation: 21 316

10My Windows 10 is deleting the Temp folder on reboots. I know it's been 5 years since your answer, but I thought I'd just leave a note here for information. – pgr – 2016-09-30T16:55:39.423

3

Because you are speaking of a server with high availability, a scheduled task is the best way to go. You could do something as simple as a vbscript or batch file that finds all files over a certain date and purges them. Adjust the frequency of the schedule based on how quickly the temp files accumulate in order to minimize the load on the server on any given run.

Thomas Maurer has a powershell script that allows a pretty high level of flexibility, such as specifying the age of the files to be removed, the folder they are to be removed from, etc.

UPDATE: Thomas Maurer's site isn't loading for me, so I ran a google search for "powershell delete files older than 30 days" and the results look promising.

music2myear

Posted 2011-08-03T12:40:56.890

Reputation: 34 957