Solved

delete sub-folders - batch script

Posted on 2006-11-07
3
427 Views
Last Modified: 2008-03-17
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
Comment
Question by:srinivas_vemla
  • 2
3 Comments
 
LVL 15

Expert Comment

by:ozymandias
ID: 17891052
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
 
LVL 15

Accepted Solution

by:
ozymandias earned 125 total points
ID: 17891063
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
 

Author Comment

by:srinivas_vemla
ID: 17891739
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now