[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2123
  • Last Modified:

DOS: delete directories with wildcard in name

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
green-greta
Asked:
green-greta
  • 3
  • 2
1 Solution
 
pbarretteCommented:
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
 
green-gretaAuthor Commented:
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
 
pbarretteCommented:
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
 
green-gretaAuthor Commented:
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
 
pbarretteCommented:
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

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now