Help with FOR /D with space in pathname

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
sfgman63
Posts: 8
Joined: 26 Nov 2009 01:32

Help with FOR /D with space in pathname

#1 Post by sfgman63 » 11 Dec 2009 16:43

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.

sxekjb
Posts: 16
Joined: 07 Nov 2009 19:13

#2 Post by sxekjb » 11 Dec 2009 17:31

try using

Code: Select all

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

DosItHelp
Expert
Posts: 239
Joined: 18 Feb 2006 19:54

#3 Post by DosItHelp » 11 Dec 2009 23:56

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?
Last edited by DosItHelp on 12 Dec 2009 23:38, edited 1 time in total.

sfgman63
Posts: 8
Joined: 26 Nov 2009 01:32

#4 Post by sfgman63 » 12 Dec 2009 02:30

Thanks sxekjb and DosItHelp, both of your suggestions worked.

Post Reply