Batch file to delete temp files across all users?

Is there some way to have a batch file that would recurse thru all the user subfolders and delete the files in all their \Temp folders at once?

Something that will do this:



del C:\Documents and Settings\*.*\Local Settings\Temp\*.*


But that actually works (the above won’t)? That is, without having to hard code the actual user names into it?

I know there are utilities that will do this but I need to do it to PCs remotely thru a network without having to install an app first.



@echo off
for /d %%d in ("%userprofile%\..\*.*") do rd "%%d\local settings	emp" /s /q


Save this as a .bat or .cmd file. Assuming you’re running an OS newer than WinME or WinNT, this will destroy all files & folders beneath the temp folder for each user profile on the machine it’s executed on.

Naturally, the ability to delete files & folders depends on security, so a low-privelege user who executes this will be unable to clean out other user’s temp files, while an admin executing this will clean the whole machine.

To test it out, insert the word “echo” between “do” & “rd” in line 2 & it will display the commands it would execute instead of actually executing them.

You don’t have to put the .cmd file on the target machine; it can reside on a central file share accessible to the target machine. But you do have to execute the code on the target machine.

If you already have a login or maintenance batch file all your machines run, you can just insert my line 2 into that file. It’s designed to not depend on or affect any surrounding execution context.

If you want to execute this code ON a central machine which reads & deletes files on OTHER machines across the network we’d need a few minor changes.

Wow! Many thanks! Does exactly what I need it to (knew there had to be a simple way to do it). I did a little with batch files back in the day, but before I did anything useful Windows came along and ruined everything. :smiley:

Thanks again…