Results 1 to 5 of 5
  1. #1
    Lounger
    Join Date
    Dec 2001
    Location
    Reston, Virginia, USA
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Batch file - Using FOR command

    I am trying zip up a lot of files, each into its own zip file. My planned approach was to use the FOR .. IN .. DO command with the enhanced substitution of FOR variable references. In looking at FOR /? help, my guess for proper command syntax is:
    FOR %~nX IN (*.bmp) DO wzzip %X.zip %X.bmp
    However, I get the error mesage
    "%~nX was unexpected at this time."

    What am I doing wrong (sorry, changing OS is not an option)?
    <img src=/S/confused.gif border=0 alt=confused width=15 height=20>

  2. #2
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    Cincinnati, Ohio, USA
    Posts
    7,089
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Batch file - Using FOR command

    If you are running it in a batch script, you need to use double %% instead of the single. Thus your sample becomes:

    <pre>FOR %%~nX IN (*.bmp) DO wzzip %%X.zip %%X.bmp</pre>

    Hope that helps!
    -Mark

  3. #3
    Lounger
    Join Date
    Dec 2001
    Location
    Reston, Virginia, USA
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Batch file - Using FOR command

    Actually, I am doing this fm the command line, not in a batch file. However, on the off-chance that it needed %% vice %, I tried that on both cmd line and batch file.
    Rcvd same error. Thanks for suggestion, though.

  4. #4
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    Cincinnati, Ohio, USA
    Posts
    7,089
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Batch file - Using FOR command

    Without see the exact code you're entering it's difficult to troubleshoot. However, at the command prompt:

    <pre>FOR %F IN ( *.bmp ) DO wzzip %F.zip %F</pre>

    Should work. I don't know the command line parameters of your Zip utility so this is a guess - but give it a shot. If it doesn't work, can you post the command and the filespec of the items you are working with?
    -Mark

  5. #5
    Lounger
    Join Date
    Dec 2001
    Location
    Reston, Virginia, USA
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Batch file - Using FOR command

    The ~n within the variable is supposed to provide just the name portion of the file name, which is why I was trying to use it. I should have given you a better example to avoid the distraction of the unfamiliar wzzip command, like:
    FOR %~nX IN (*.BMP) DO @ECHO %X
    which would fail in the same manner.

    However, a little help from a friend here just shed light on what the help file was trying to say. The substitution goes into the Command (DO) portion of the batch command. The proper syntax for my problem is:
    FOR %X IN (*.bmp) DO wzzip %~nX.zip %X

    Thanks for your help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •