?
Solved

delete multiple directories from command line

Posted on 2008-10-17
7
Medium Priority
?
1,141 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 4

Expert Comment

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

Accepted Solution

by:
michote earned 1000 total points
ID: 22745525
0
 

Author Comment

by:caw01
ID: 22745584
Is that a VB script?  How do I run that?
0
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
LVL 4

Expert Comment

by:michote
ID: 22745708
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 85

Assisted Solution

by:oBdA
oBdA earned 1000 total points
ID: 22745987
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
ID: 22746069
That solution is also in the Link I posted.
0
 

Author Closing Comment

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

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Know what services you can and cannot, should and should not combine on your server.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

765 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