Take the 2-minute tour ×

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...


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

share|improve this question

2 Answers 2

up vote 7 down vote accepted

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.

share|improve this answer
Agree. Everyone should clean up after themselves, even applications. –  Nifle Aug 3 '11 at 13:46
Mother was right?!?! –  music2myear Aug 3 '11 at 14:00
@music2myear: Yes, yes she was. :-) –  afrazier Aug 3 '11 at 14:10
Hey, I guess the good news is I'll have something worthwhile to thank her for next mother's day. ;) –  music2myear Aug 3 '11 at 14:13

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.

share|improve this answer

Your Answer


