tags:

views:

27

answers:

1

Hey all-

I'm trying to run a command on all lines of a txt file through a batch file. I'm struggling to escape the characters in the IN () clause of the for loop.

This works:

for /F %%i IN (C:\test.txt) DO echo %%i

These don't:

for /F %%i IN (C:\Documents and Settings\user\Desktop\test.txt) DO echo %%i
for /F %%i IN ("C:\Documents and Settings\user\Desktop\test.txt") DO echo %%i
for /F %%i IN ('C:\Documents and Settings\user\Desktop\test.txt') DO echo %%i

Any idea how to get cmd to register that full path? Thanks-

Jonathan

A: 

Try the usebackq option of the for command.

for /F usebackq %%i IN ('C:\Documents and Settings\user\Desktop\test.txt') DO echo %%i
krock
Yup, that did it. for /F usebackq %%i IN ("C:\Documents and Settings\user\Desktop\test.txt") DO echo %%i
Jonathan