• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 450
  • Last Modified:

delete sub-folders - batch script

I have my project solution folder that contains multiple projects. These project folders again contain "bin" and "obj" folders. I want to write a small batch script that deletes these bin and obj folders. I am using Windows XP and don't find deltree command. And rd /s needs the folder name. Am I missing any other command? how can i delete sub-folders?
0
srinivas_vemla
Asked:
srinivas_vemla
  • 2
1 Solution
 
ozymandiasCommented:
OK. Be real careful with this :

for /D %d in (*) DO rd %d\bin

This is the for command.
For more details type for /? at a command prompt.

The above command says :

for  - command
/D - match directories only
%d a variable tp represent each item in the set
in (*) - this is a set which can use wildcards but it can be a list like (dir1,dir2,dir3,etc).
DO command - the command to execute for each item in the set
0
 
ozymandiasCommented:
this command will execute the command rd directoryname/bin for each and every directory in the current working directory
you can then do another one that does :

for /D %d in (*) DO rd %d\obj
0
 
srinivas_vemlaAuthor Commented:
thanks gzymandias,
the for look was helpful...
but, I don't want to add "\obj" to all the child directories, but rather want to search these folders and then remove them...

so I came up with this:

dir /b /s bin, obj > temp.txt
for /F "delims=" %%d in (temp.txt) do rd /s /q "%%d"

and it works...
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now