?
Solved

DOS: delete directories with wildcard in name

Posted on 2003-02-20
5
Medium Priority
?
2,118 Views
Last Modified: 2011-09-20
Hello! I need to delete a list of directories (list is   determined by a wildcard search).  e.g. delete all directories called "Test*" in "C:\MyProject"

I'd like to use:
rmdir /s /q C:\MyProject\Test*
but this gives a syntax error.

Can anyone give me a simple work around?

Thanks for your help!
0
Comment
Question by:green-greta
[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
  • 3
  • 2
5 Comments
 
LVL 10

Accepted Solution

by:
pbarrette earned 600 total points
ID: 7987954
Hi Green-Greta,

Try this line for WinNT/2K:
FOR /F %I IN ('DIR /AD /B C:\MyProject\TEST*') DO (RD /S /Q C:\MyProject\%I)

If you are going to use this in a batch file, you must use this:
FOR /F %%I IN ('DIR /AD /B C:\MyProject\TEST*') DO (RD /S /Q C:\MyProject\%%I)

pb
0
 

Author Comment

by:green-greta
ID: 7988868
pb - thank you this works perfectly!

Is there a way to cut and paste a command into DOS? Or some kind of shortcut that will repeat the previous command?  Would be very useful for these long commands!

Thank you again!
0
 
LVL 10

Expert Comment

by:pbarrette
ID: 7989262
Hi Green-Greta,

There are a few ways that you can do this.

1) Make a batchfile:
Open Notepad and paste the command into it.
Save the file as "FILENAME.BAT" where FILENAME is something that you can remember. Like DELDIRS, or something similar. Place the file in a directory where you can easily find it later.

When you need to run the command, either double-click on it, or use the command line to run it.

For example. To create a batchfile from the command in my last post. You would cut and pase the following into Notepad, then save it as DELDIRS.BAT:
:: -------DELDIRS.BAT--------
@ECHO OFF
FOR /F %%I IN ('DIR /AD /B C:\MyProject\TEST*') DO (RD /S /Q C:\MyProject\%%I)
:: -------DELDIRS.BAT--------

2) Use the command history:
If you have run some commands at the DOS prompt and wish to run one of those commands again, you can use the UP/DOWN-ARROW keys to scroll through your command history. When the command-line is displaying the command you need, you can either hit ENTER, or you can use the LEFT/RIGHT-ARROW keys to move through and edit the command. When you are finished editing the command, you can hit ENTER to run it again.

If you need more help, feel free to ask. In the meantime, some good, basic batchfile information can be found here:
http://www.computerhope.com/batch.htm
http://www.tnd.com/camosun/elex130/dosbatchtutor1.html

Some of the more advanced resrouces that I use are:
http://www.robvanderwoude.com/index.html
http://www.ericphelps.com/batch/

Hope this helps,
pb
0
 

Author Comment

by:green-greta
ID: 8008130
Thank you for these suggestions!  The websites look helpful.  I couldn't get the command history to work, though.  (arrow keys didn't do anything...) Is there a setting I need to adjust?  
0
 
LVL 10

Expert Comment

by:pbarrette
ID: 8009709
Hi Green-Greta,

Make sure that you have the Command History enabled. With the command-line window open, click on the icon in the top-left corner of the window. From the menu, select "Properties". In the "Properties" window, select the "Options" tab. In the section labeled "Command History" increase your "Buffer Size" to at least "50" and your "Number of Buffers" to at least "4". When you hit the OK button at the bottom, you should be asked if you want to "Apply to current window" or "Modify the shortcut". Select "Modify the shortcut" to ensure the settings are kept for the next time.

These are the default buffer numbers for Win2k Pro.

Hope this helps,
pb
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month9 days, 19 hours left to enroll

762 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