views:

140

answers:

2

Currently, my simple batch script looks like this:

@echo off
for /D /r C:\myprojects\AIS\ %%G in (_svn) do rd /S /Q %%G
pause

Unfortunately, this skips any directories with a space character in them, such as a directory called "My Projects". How do I get around this and make sure I traverse that directory as well?

+1  A: 

Can you put quotes around the directory name?

I tried this: for /D /r C:\electionscanadaprojects\AIS\ "%%G" in (_svn) do rd /S /Q "%%G", since %%G holds the directory name, but no dice.
Chris
Do you have to escape the quotes somehow? I'm just guessing here, I'm not a DOS guy (this is DOS, right?)
Yes it is dos. I don't believe you have to escape the quotes, as this normally works if you've given the direct path to the directory. However, it being stored in a variable is causing me issues, I think. (I'm knew to batch scripting. May be wrong)
Chris
So this is no good, right? for /D /r C:\electionscanadaprojects\AIS\ \"%%G\" in (_svn) do rd /S /Q "%%G"
A quick guess, shouldn't the quotes just be around the second instance of %%G, and not around the first one?
Philip Kelley
That would make too much sense.
+2  A: 

Hmmm... it seems to work for me. Have you tried echo instead?

C:\tmp> TREE /A C:\tmp\xxx
C:\TMP\XXX
\---one one
    \---two two

C:\tmp> FOR /D /R c:\tmp\xxx %I IN (_svn) DO @ECHO RD "%I"
RD "c:\tmp\xxx\_svn"
RD "c:\tmp\xxx\one one\_svn"
RD "c:\tmp\xxx\one one\two two\_svn"

You probably need quotes around your argument to rmdir. If you want to be truly paranoid, then use %~I instead to protect against the chaos that FOR /D /R ... %I IN ("_svn") would otherwise cause.

D.Shawley