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.

3 Answers 3

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
2
  • You absolute Gem! Does the job perfectly, thanks very much!! May 1, 2012 at 14:41
  • You're welcome :)
    – RomeNYRR
    May 1, 2012 at 14:46
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(

1
  • 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 May 1, 2012 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.