Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Clearing out the Windows Temp folder

Jul
304
0
If I want to delete everything in the C:\WINDOWS\TEMP folder (but NOT the folder itself in windows 10, can I use

del /s /x /y /z c:\windows\temp\

?

Is that the "best" way to do it?

Regards,
Chuck Billow
 
It would probably work. I'd recommend not deleting files that were modified within in the last 24 hours though as some applications write files and expect them to be there a few minutes later. Installers, in particular, get cranky when you delete their temporary files before they're done.

I do something a bit different:

Code:
cdd c:\windows\temp
set maxage=2
del /[d-%@eval[6000+%[maxage]],+6000] /x /y /z .

do olddir IN /[d-%@eval[6000+%[maxage]],+6000] /a:d *
   del /X /Y /Z /S %@requote[%@full[%@requote[%[olddir]]]]
enddo

I hacked this up from some BTMs that do far more complex cleanups across multiple directories and for different purposes -- When I receive files from a customer, I need to retain them for no more than "x" days (depending on the type of file), but I often get RAR/ZIP files with older files contained within. The intention is to only hit files or directories older than 2 days, but not files in subdirectories which happen to be older. This happens with installers, they'll often create a temporary directory while they're running but the files within will have older dates.

Test carefully, there is no guarantee that I didn't screw up copy/pasting the syntax. I don't remember why I did the date math quite like that, but I think it solved some other case where I use %[maxage] elsewhere and just re-used it? Either way, it seems to work.
 

Similar threads

Back
Top