Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 3 down vote accepted

Throw this one liner into a bat file:


  • /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"
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


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.