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

Author Topic: XP: how to have one batch file create another with FOR Variables  (Read 4116 times)

0 Members and 1 Guest are viewing this topic.

crp

    Topic Starter


    Newbie

     I want to have a batch file create a series of batch files , each of which use a variable.
    the final output should read:

    for %%V in (*.vnc) do fixit %%V

    I tried a batch file
    Code: [Select]
    for /L %%Q in (0,1,3) do echo for %%V in (*%%Q.vnc) do fixit %%V > %%Q_Fix.batand
    Code: [Select]
    for /L %%Q in (0,1,3) do echo for ^%%V in (*%%Q.vnc) do fixit ^%%V > %%Q_Fix.bat
    but they didn't work, as the resulting batch files (ie: 3_fix.bat) came out:

    for %V in (*3.vnc) do fixit %V

    How can I 'protect' the double percentage sign in the echo output to the file?
    (Preview did not work in my browser, so sorry if this didn't come out formatted correctly)

    Dias de verano

    • Guest
    Re: XP: how to have one batch file create another with FOR Variables
    « Reply #1 on: January 26, 2009, 03:45:06 PM »
    the final output should read:

    for %%V in (*.vnc) do fixit %%V

    Then why is the %%Q present here?

    for /L %%Q in (0,1,3) do echo for %%V in (*%%Q.vnc) do fixit %%V > %%Q_Fix.bat

    Quote
    How can I 'protect' the double percentage sign in the echo output to the file?

    The escape char for a percent sign is... a percent sign. That is, to echo one percent sign from a batch, you use two in the code.

    Code: [Select]
    @echo off

    for /L %%Q in (0,1,3) do echo for %%%%V in (*%%Q.vnc) do fixit %%%%V > %%Q_Fix.bat

    for /L %%Q in (0,1,3) do (
        echo %%Q_Fix.bat:
        echo.
        type %%Q_Fix.bat
        echo.
        )


    Code: [Select]
    0_Fix.bat:

    for %%V in (*0.vnc) do fixit %%V

    1_Fix.bat:

    for %%V in (*1.vnc) do fixit %%V

    2_Fix.bat:

    for %%V in (*2.vnc) do fixit %%V

    3_Fix.bat:

    for %%V in (*3.vnc) do fixit %%V

    crp

      Topic Starter


      Newbie

      Re: XP: how to have one batch file create another with FOR Variables
      « Reply #2 on: January 26, 2009, 04:14:40 PM »
      the final output should read:

      for %%V in (*.vnc) do fixit %%V

      Then why is the %%Q present here?

      for /L %%Q in (0,1,3) do echo for %%V in (*%%Q.vnc) do fixit %%V > %%Q_Fix.bat
      I do not understand the question.

      Quote
      Quote
      How can I 'protect' the double percentage sign in the echo output to the file?

      The escape char for a percent sign is... a percent sign. That is, to echo one percent sign from a batch, you use two in the code.

       :) yes  :)
      Code: [Select]
      for /L %%Q in (0,1,3) do echo for %%%%V in (*%%Q.vnc) do fixit %%%%V > %%Q_Fix.bat worked perfectly, as wanted.

      Where is that nugget of information about the ESCape character for '%' being '%' ?
      I searched quite a few places for 'dos percentage escape'
      THANK YOU!

      Dias de verano

      • Guest
      Re: XP: how to have one batch file create another with FOR Variables
      « Reply #3 on: January 27, 2009, 12:21:55 AM »
      the final output should read:

      for %%V in (*.vnc) do fixit %%V

      Then why is the %%Q present here?

      for /L %%Q in (0,1,3) do echo for %%V in (*%%Q.vnc) do fixit %%V > %%Q_Fix.bat
      I do not understand the question.

      You stated that the output should be:

      for %%V in (*.vnc) do fixit %%V

      (There is no number between the asterisk and 'vnc')

      Yet in your code you show

      echo for %%V in (*%%Q.vnc)

      Which means you want to see *0.vnc, *1.vnc, *3.vnc. Which is different.

      That's all.

      Quote
      Where is that nugget of information about the ESCape character for '%' being '%' ?
      I searched quite a few places for 'dos percentage escape'
      THANK YOU!

      Well, perhaps if you tried "percent sign" you would have found something, and we're not in DOS land...

      Here for example

      http://www.google.com/search?source=ig&hl=en&rlz=&=&q=escape+percent+sign&btnG=Google+Search&meta=lr%3D

      the 2nd result leads to

      http://www.robvanderwoude.com/escapechars.html