Recursively delete files on a windows box

Computer directory listing

Image via Wikipedia

I had a large amount of files to delete from a old backup server. I didn’t want to do it through the GUI because this machine did not have much RAM. So I was looking for the syntax to do it on the command line and I found two good resources on it I wanted to share with you.

Tech-recipes had the first quick and easy solution

From the cmd line you can run

del /s *.tmp

It will delete all files ending in tmp from the current directory and all sub directories.

Next daniweb had a post on a batch file to

FOR /F "tokens=*" %%G IN ('DIR /B /AD /S *.svn*') DO RMDIR /S /Q %%G

If you're thinking WTF?:
 
DIR /B /AD /S *.svn* lists all files that are named ".svn"
/B makes the output "bare" with nothing but the file name
/AD only lists directories
/S Displays files in specified directory and all subdirectories if  they match the listing criteria
RMDIR /S /Q [path/name] deletes the directory [path/dir] and all of it's childrenFOR /F processes each item (in this case directories) in the set IN ('[command]') by executing the DO [command]%%G is a parameter, which in this example is a directory name"tokens=*" says that all the characters output in a line (i.e. by the dir command) are assigned to the parameter %%G
See the Microsoft Command Line Reference for more on FOR:
Enhanced by Zemanta

About the Author

Jason Benway Has Written 1362 Articles For Us!

I am the admin of this site and enjoy enterprise technologies and gadgets.
Getting The Latest Tweet...
Did you know Jason has a website? Go see what you're missing...

Related posts:

  1. Five command line tools to detect Windows hacks
  2. Moving DHCP from windows 2003 to windows 2008
  3. PowerShell: Microsoft releases a new Windows Command Prompt
  4. Causes and Tips to Resolve the STOP Error When Booting Windows XP
  5. Do you store PST files on file servers?

Related posts brought to you by Yet Another Related Posts Plugin.

No Comments


CommentLuv badge

This blog uses premium CommentLuv which allows you to put your keywords with your name if you have had 3 approved comments. Use your real name and then @ your keywords (maximum of 3)