1.

Solve : DOS Batch - Remove all Directories with a specific?

Answer»

Looking for syntax to remove all folder on a machine with a specified
NAME structure and a wildcard.

Ex.

All folders with the name structure "BACKUP for 12-31-05", "Backup for 07-05-04"

So any folder with the parameter "Backup for *"

Is this possible in DOS?
Is this really DOS or some version of the command shell under Windows? This may work:

Code: [Select]for /f "tokens=* delims=" %i in ('dir /a:d /b backup*') do rd "%i"
Note: the above example is from the command line. For a batch file double up on all the % symbols.

 8-)This would be a command shell under windows. This would have to be
a batch file run on multiple computers.

By double up do you mean just add another like such:

for /f "tokens=* delims=" %%i in ('dir /a:d /b backup*') do rd "%%i"

One more question... where is the drive specified, or is it just specified
by the working DIRECTORY it is being run under?

Thanks for your help.You have it right for a batch file. Code was written for the current directory. If you add a path to point to your directory structure, you may have to add the /s switch. Be careful, you may get more than you wish for.

Code: [Select]for /f "tokens=* delims=" %%i in ('dir /a:d /b /s c:\dir1\dir2\backup*') do rd "%%i"

PERSONALLY I would change the RD command to ECHO, and test this out before committing to deleting directories.

 8-)



Discussion

No Comment Found