2

Have tried to google this, but I always seem to get results relating to .tmp files, which isnt really any use.

I have only a basic understanding of batch files, but I think I need something like this:

rmdir "D:\*.tmp"

Windows update seems to be dumping all of it's .tmp folders onto our D drive, as it has the most free space. Fine, but it doesnt then delete them afterwards.

I'm looking to write a batch file, that will go through and delete any folder that has .tmp at the end.

MadHatter
  • 78,442
  • 20
  • 178
  • 229
James Edmonds
  • 1,653
  • 10
  • 36
  • 58

3 Answers3

4

Throw this one liner into a bat file:

FOR /D /R c:\FOLDERLOCATION %%X IN (*.tmp) DO RMDIR /S /Q "%%X"

  • /D - For Directory
  • /R - Recursive

This will remove the folders ending in tmp and anything under it. If you want to get fancy you can run it like this:

@echo off
set dir="c:\FOLDERLOCATION\"
FOR /D /R %dir% %%X IN (*.tmp) DO RMDIR /S /Q "%%X"
pause
exit
RomeNYRR
  • 1,439
  • 9
  • 16
1

If you add a /S to the end of that line, I believe it will delete all specified folders and sub-folders that match your wildcard search. If you can confirm that it works, then you can throw it into Notepad and save it as a .bat file. Unfortunately, I'm old school and don't know how to do it the Powershell way. :o(

jscott
  • 24,204
  • 8
  • 77
  • 99
  • well I looked for the powershell equivelent, which appears to be "Remove-Item C:\Test* -recurse". If I can not find a batch version to do the same, I will just install powershell on the server. Thanks – James Edmonds May 01 '12 at 14:03
0

I've improved @RomeNYRR's answer - thanks @RomeNYRR!

The command now echoes deleted folders and hides "element not found" error messages:

for /d /r . %X in (*.tmp) do @rmdir /s /q "%X" 2> nul && @echo Deleted %X

Great if you need to clean after your compiler... ;)

for /d /r . %X in (bin obj) do @rmdir /s /q "%X" 2> nul && @echo Deleted %X