Page 1 of 1

Help with FOR /D with space in pathname

Posted: 11 Dec 2009 16:43
by sfgman63
My FOR loop works when there are no spaces in the path name

Code: Select all

FOR /D %%i IN (C:\FCTLogs\FirstRun\TestLogs\ABC*) DO RMDIR /S /Q %%i


But when there is a space it doesn't work (tried enclosing in quotes and still didn't work):

Code: Select all

FOR /D %%i IN (C:\Documents and Settings\TestLogs\ABC*) DO RMDIR /S /Q %%i


I tried setting the path to a variable and it still didn't work
set logdir=C:\Documents and Settings

Thanks for all the help.

Posted: 11 Dec 2009 17:31
by sxekjb
try using

Code: Select all

FOR /D %%i IN (C:\docume~1\TestLogs\ABC*) DO RMDIR /S /Q %%i 

Posted: 11 Dec 2009 23:56
by DosItHelp
Or put quotes around both the search pattern ("C:\FCTLogs\FirstRun\TestLogs\ABC*") and the substitution variable ("%%i").

Code: Select all

FOR /D %%i IN ("C:\FCTLogs\FirstRun\TestLogs\ABC*") DO RMDIR /S /Q "%%i"

DosItHelp?

Posted: 12 Dec 2009 02:30
by sfgman63
Thanks sxekjb and DosItHelp, both of your suggestions worked.