Solved

delete multiple directories from command line

Posted on 2008-10-17
7
1,125 Views
Last Modified: 2010-04-21
Hello,

I am trying to delete a bunch of directories from the command line in Windows.  I am getting  syntax not correct error.  Al of the folders I want to delete begin with IMG.

The command I am running is RD img* /s /q.

If I put in the full folder name, it works, but I need to run this from a batch file and the folder names are always different at the end.
0
Comment
Question by:caw01
  • 4
  • 2
7 Comments
 
LVL 4

Expert Comment

by:michote
Comment Utility
wild cards are not permited with this command, you will need a different utility
0
 
LVL 4

Accepted Solution

by:
michote earned 250 total points
Comment Utility
0
 

Author Comment

by:caw01
Comment Utility
Is that a VB script?  How do I run that?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 4

Expert Comment

by:michote
Comment Utility
http://en.wikipedia.org/wiki/VBScript

The short version is you already have it installed, just copy the script on notepad, and give it a .vbs extention. that is it. run it.
0
 
LVL 82

Assisted Solution

by:oBdA
oBdA earned 250 total points
Comment Utility
It's actually a simple one-liner in the command prompt:
for /d %a in (img*) do @echo rd /s /q "%a"

"for /d" will create a loop and process every *d*irectory in the current folder beginning with "img"; the currently processed folder will be in the variable %a (enter "help for" for details).
The command above will not do anything except echo out the rd "commands" it would otherwise run, so that you can test it.
To run it for real, just remove the @echo (the "@" in front of a command will just suppress echoing the command itself):
for /d %a in (img*) do rd /s /q "%a"
0
 
LVL 4

Expert Comment

by:michote
Comment Utility
That solution is also in the Link I posted.
0
 

Author Closing Comment

by:caw01
Comment Utility
I used the the vb script, but the other command woul dprobably have worked too...
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Welcome to my series of short tips on migrations. Whilst based on Microsoft migrations the same principles can be applied to any type of migration. My first tip Migration Tip #1 – Source Server Health can be found here: http://www.experts-exchang…
This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

772 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

15 Experts available now in Live!

Get 1:1 Help Now