Link to home
Start Free TrialLog in
Avatar of FCB_IT
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,
Avatar of MarkieS
MarkieS
Flag of United Kingdom of Great Britain and Northern Ireland image

This clears out all temp stuff on all user profiles on your local machine.  Just amend your starting folder..


@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
Avatar of FCB_IT
FCB_IT

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?
ASKER CERTIFIED SOLUTION
Avatar of MarkieS
MarkieS
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of FCB_IT

ASKER

That took care of it. I see my syntax error now. Thanks for your help!