views:

31

answers:

1

I am trying to write a batch script with a section that ouputs your drive mappings to a text file, so i can restore it later once i wipe out the machine. I came up with this for loop to do it, but its acting differently when its a batch script versus running the command itself.

This is the actual line of code:

FOR /F "tokens=1,2" %i in (H:\mappings2.dat) do @echo %i %j

When i copy and paste the command from the script to the command window it works fine. When I run the batch script from a command window it outputs this:

FOR /F "tokens=1,2" \mappings2.dat) do @echo j
\mappings2.dat) was unexpected at this time.

Im guessing there is some little trick that will fix it, but i cant find anything on google...

oh, in case your wondering here is that section of script:

net use > H:\mappings0.dat

findstr /r [A-Z]: H:\mappings0.dat > H:\mappings2.dat

FOR /F "tokens=1,2" %i in (H:\mappings2.dat) do @echo %i %j >> H:\mappings1.dat
+1  A: 

Nevermind, I figured it out...for loop variables have to have double percentage signs, while the command line versions only use single percentage sign for loop variables...I added another % to each variable in my for loop and now it works perfectly.

JVM