FCB_IT
asked on
How do I write a batch file that will delete all temporary files (.tmp, doc, etc.) in a folder and its subfolders
I am trying to write a batch file that deletes all temporary files, hidden and not hidden, in a folder and its subfolders . The batch file I have started is like this.
Del C:\Temp\ /S ~*.tmp
What this ends up doing is deleting every file in every folder in Temp. What do I need to do to make this only delete temporary files (doc, tmp, etc), hidden and not hidden? I have tried the /AH command and this essentially does the same thing, but deleting every hidden file instead.
Thanks for the help,
Del C:\Temp\ /S ~*.tmp
What this ends up doing is deleting every file in every folder in Temp. What do I need to do to make this only delete temporary files (doc, tmp, etc), hidden and not hidden? I have tried the /AH command and this essentially does the same thing, but deleting every hidden file instead.
Thanks for the help,
ASKER
Sorry, I should have been a little more specific. I am trying to clean up a shared folder that many users store Words, Excel, etc docs in. I just need to delete the temp files from that folder and its subfolders and maintain the normal word docs.
Markie, would that batch you wrote work in this case?
Markie, would that batch you wrote work in this case?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That took care of it. I see my syntax error now. Thanks for your help!
@echo off
cls
Rem Delete all temporary stuff
Rem _________________________
echo.
echo Ensure all applications are closed as work may be lost.
echo.
Pause
rem Clear all local user "Temporary Internet Files"
FOR /F %%A IN ('DIR/B "C:\Documents and Settings"') DO DEL/S/F/Q "C:\Documents and Settings\%%A\Local Settings\Temporary Internet Files\*.*"
FOR /F %%A IN ('DIR/B "C:\Documents and Settings"') DO RD/S/Q "C:\Documents and Settings\%%A\Local Settings\Temporary Internet Files\"
rem Clear Local User Temp files
FOR /F %%A IN ('DIR/B "C:\Documents and Settings"') DO DEL/S/F/Q "C:\Documents and Settings\%%A\Local Settings\Temp\*.*"
FOR /F %%A IN ('DIR/B "C:\Documents and Settings"') DO RD/S/Q "C:\Documents and Settings\%%A\Local Settings\Temp\"
rem Clear Windows Temp folders
DEL/S/F/Q c:\windows\temp
DEL/S/F/Q c:\windows\prefetch