Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to remove directories of the following format:

C:\Program Files\FogBugz\Plugins\cache\PluginName@example.com_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_??", ...cache\"*, ...cache"\*, 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
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\PluginName@example.com_*") 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
@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

You can escape the space with the ^ character: C:\Program^ Files\FogBugz\Plugins\cache\PluginName@example.com_*

share|improve this answer
That doesn't seem to work (although it should: ). 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

Your Answer


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.