1.

Solve : %%a empty first in in for do loop?

Answer»

FOR /F %%A in (content.txt) do echo %%A

Produces

c:\RMToolkit>FOR /F %A in (content.txt) do echo %A

the first time through and then proceeds to correctly capture each line of data in the file.

What is wrong? how do I prevent this from happening?

A more detailed echo output:

c:\RMToolkit>FOR /F %A in (content.txt) do (echo copy /y \\spwebdev\%A \\spweb01
\%A )

c:\RMToolkit>(echo copy /y \\spwebdev\ohanaccs\provider\mickeymouse.xml \\spweb0
1\ohanaccs\provider\mickeymouse.xml )
copy /y \\spwebdev\ohanaccs\provider\mickeymouse.xml \\spweb01\ohanaccs\provider
\mickeymouse.xml

c:\RMToolkit>(echo copy /y \\spwebdev\hawaii\provider\pharmacy.xml \\spweb01\haw
aii\provider\pharmacy.xml )
copy /y \\spwebdev\hawaii\provider\pharmacy.xml \\spweb01\hawaii\provider\pharma
cy.xml

c:\RMToolkit>(echo copy /y \\spwebdev\hawaii\provider\quality.xml \\spweb01\hawa
ii\provider\quality.xml )
copy /y \\spwebdev\hawaii\provider\quality.xml \\spweb01\hawaii\provider\quality
.xml

c:\RMToolkit>(echo copy /y \\spwebdev\ohanaccs\provider\coverage_determination.x
ml \\spweb01\ohanaccs\provider\coverage_determination.xml )
copy /y \\spwebdev\ohanaccs\provider\coverage_determination.xml \\spweb01\ohanac
cs\provider\coverage_determination.xml

Again ... the first ITERATION does not contain the first line of data in the file, but leaves it empty. Below is the file contents.

ohanaccs\provider\mickeymouse.xml
hawaii\provider\pharmacy.xml
hawaii\provider\quality.xml
ohanaccs\provider\coverage_determination.xml

From what I understand it is outputting this to tell you what the 'For' command "compiles" to. If you use variables WITHOUT delayed expansion they will be prioritized before the loop is processed.

for /f "tokens=2 delims==" %%B in ('set colr') do if not %%B equ %win.colr% set win=0
%win.colr% would be replaced with it's value before the loop executed. To get around this, we would enable delayed expansion and use:
for /f "tokens=2 delims==" %%B in ('set colr') do if not %%B equ !win.colr! set win=0
which would allow the value of win.colr to change within the loop. What you are DESCRIBING is a means to debug which is showing you exactly what loop will run. If you do not wish for it, I'm sure you can write a 'for /f' loop to remove it, but it would be kinda pointless and quite a headache.If you are typing the command at the PROMPT, use only single percent symbols:
FOR /F %A in (content.txt) do echo %A

use double ones in a batch file where the %% is evaluated as %

PUT this at the top of your script.
Code: [Select]@echo off



Discussion

No Comment Found