Quote from MS Technet:
Q: Hey, Scripting Guy! How can I delete folders based on a wildcard character? For example, how can I delete all the folders whose name starts with December?
A: Hey, RR. Well, that depends. If you’re running Windows XP or Windows Server 2003, you can actually use a wildcard character to identify and then delete all the folders whose name starts with December. If you’re running Windows 2000, you can achieve the same net result: you can identify and delete all the folders whose name starts with December. It’s just that you’ll have to do it in a more clumsy, brute-force fashion.
The Scripting Guy provides a .vbs script to enhance the Window 2000 del.exe and rd.exe command and support wildcards. Here is a 1-line shell script:
rdw.cmd (you could add /q to run the script quite):
1 2 | echo delete directory %1 for /f “tokens=*” %%i in (‘dir %1 /b’) do rd “%%i” /s |
Example:
1 | rdw.cmd “c:program filesa*” |
This should be easier to use..
One Comment
1 Steve wrote:
Great tip and it helps me out a bunch, though I’d like to point out that I had to change the command to the following to ensure that the directories are deleted out of the proper parent directory (with quiet mode):
for /f “tokens=*” %%i in (‘dir %1 /b’) do rd %1″%%i” /s/q