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,
FCB_ITAsked:
Who is Participating?
 
MarkieSCommented:
Near enough as you had it

DEL C:\TEMP\*.tmp /S
0
 
MarkieSCommented:
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
0
 
FCB_ITAuthor Commented:
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?
0
 
FCB_ITAuthor Commented:
That took care of it. I see my syntax error now. Thanks for your help!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.