delete multiple directories from command line


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.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

wild cards are not permited with this command, you will need a different utility

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
caw01Author Commented:
Is that a VB script?  How do I run that?
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).


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.
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"
That solution is also in the Link I posted.
caw01Author Commented:
I used the the vb script, but the other command woul dprobably have worked too...
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.