Home » Questions » Computers [ Ask a new question ]

How to delete files recursively in Windows XP in certain directory

How to delete files recursively in Windows XP in certain directory

I have many many directories. Let's say dir1, dir2, dir3 and each directory has a subdirectory named tempdir.

Asked by: Guest | Views: 147
Total answers/comments: 1
bert [Entry]

"This may not be for everyone but I love it, understand a few things first.
1) I like and use command line stuff because create batch files to do redundant tasks is preferable to me.
2) I always extend my command line capabilites using standard gnu linux commands ported to windows. They can be found at http://sourceforge.net/projects/unxutils/. I just take the exe files I am interested out of the ZIP file (they are located in the /usr/local/wbin directory of the ZIP) and place them in some directory in my path. Because I use them so often I actually place them all in a /unix directory and put that first in the path.
3) For this task the utilities specifically needed are find and rm. If you get a conflict with the find command and the Windows find, just use the whole path in the command.

To focus in on just deleting the tempdir directories, assuming that there may be other files or directories within dir1 dir2 dir3, I would do the following.

Go to the directory which is the parent of dir1 dir2 dir3 and run

find . -name tempdir -type d -depth -ok rm -rf {} ;

meaning the following

find . - Start in this directory and find something for me.
-name temdir - The name of what we are looking for.
-type d - Look for directories (named as above).
-depth - Look down the tree first so if you remove something it won't complain.
-ok rm -rf {} ; - The real power ok just means to ask before doing anything,

if ok is replace with exec then it will just to it.
So do the following rm -rf on all matching ""found entries"" or in other words
remove recursively forcing removal all directories named temdir"