Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 3 down vote accepted

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
share|improve this answer
    
You absolute Gem! Does the job perfectly, thanks very much!! –  Eds May 1 '12 at 14:41
    
You're welcome :) –  RomeNYRR May 1 '12 at 14:46

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(

share|improve this answer
    
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 –  Eds May 1 '12 at 14:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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