Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: %%a empty first in in for do loop  (Read 3927 times)

0 Members and 1 Guest are viewing this topic.

kzuber

    Topic Starter


    Newbie

    • Experience: Familiar
    • OS: Windows 7
    %%a empty first in in for do loop
    « on: March 05, 2014, 07:30:10 AM »
    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

    « Last Edit: March 05, 2014, 08:31:19 AM by kzuber »

    Lemonilla



      Apprentice

    • "Too sweet"
    • Thanked: 70
    • Computer: Specs
    • Experience: Experienced
    • OS: Windows 7
    Re: %%a empty first in in for do loop
    « Reply #1 on: March 05, 2014, 08:34:58 AM »
    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.
    Quote from: patio
    God Bless the DOS Helpers...
    Quote
    If it compiles, send the files.

    gpl



      Apprentice
    • Thanked: 27
      Re: %%a empty first in in for do loop
      « Reply #2 on: March 05, 2014, 08:53:43 AM »
      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 %


      Squashman



        Specialist
      • Thanked: 134
      • Experience: Experienced
      • OS: Other
      Re: %%a empty first in in for do loop
      « Reply #3 on: March 05, 2014, 03:44:40 PM »
      put this at the top of your script.
      Code: [Select]
      @echo off