Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want to remove directories of the following format:

C:\Program Files\FogBugz\Plugins\cache\[email protected]_NN

NN is a number, so I want to use a wildcard (this is part of a post-build step in Visual Studio). The problem is that I need to combine quotes around the path name (for the space in Program Files) with a wildcard to match the end of the path. I already found out that rd is the remove command that accepts wildcards, but where do I put the quotes? I have tried no ending quote (works for dir), ...example.com*", ...example.com"*, ...example.com_??", ...cache\"[email protected]*, ...cache"\[email protected]*, but none of them work.

(How many commands to remove a file/directory are there in Windows anyway? And why do they all differ in capabilities?)

share|improve this question
    
I usually use rm -rf for this. There are several ports of Unix coreutils to Windows: UnxUtils, the MSYS package of MinGW, Cygwin (yecch), Micros~1 own Services for Unix... –  grawity Jun 2 '10 at 12:42
add comment

2 Answers

up vote 3 down vote accepted

rmdir does not support wildcards. It only accepts complete filenames.

You can try this alternative:

for /d %f in ("C:\Program Files\FogBugz\Plugins\cache\[email protected]_*") do rmdir /s/q "%~f"

(The /s/q arguments to rmdir do the same thing as rm -rf on Unix. The for /d argument makes for match directory names instead of file names.)


Remember that the cmd.exe shell does not do wildcard expansion (unlike Unix sh) -- this is handled by the command itself.

share|improve this answer
    
Your alternative works in cmd.exe, but not as a VS post-build step (The command exited with code 255). And indeed, from the (conflicting) info om the web, I thought that rd did support wildcards, and rmdir didn't. But it appears they are synonyms? And indeed, I was expecting expansion by the shell, not the individual commands. –  Jan Fabry Jun 2 '10 at 14:48
1  
@Jan: That might be because for is a cmd.exe built-in. You could try putting it in a .cmd script and run that instead. (Beware: for inside batch scripts requires %%x instead of %x.) And yes, rd and rmdir are the same thing. –  grawity Jun 2 '10 at 15:02
add comment

You can escape the space with the ^ character: C:\Program^ Files\FogBugz\Plugins\cache\[email protected]_*

share|improve this answer
    
That doesn't seem to work (although it should: msdn.microsoft.com/en-us/library/kcc7tke7(VS.80).aspx ). I use the following code: rmdir /s /q C:\Program^ Files\FogBugz\Plugins\cache\$(TargetName)* in VS or in cmd.exe (with TargetName replaced of course), and I get The system cannot find the file specified. / The system cannot find the path specified. in both places. –  Jan Fabry Jun 2 '10 at 11:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.