Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Truncated file name when compressing using batch file.

2014-02-20
2014-02-21
  • Steven Wood
    Steven Wood
    2014-02-20

    I am using the below command to zip files into individual zip files for emailing out.

    For /f %%A in ('dir /b *.xls') do "C:\Program Files\7-Zip\7z.exe" a -tzip -pexternal "%%~nA.zip" "%%A"

    The problem I have relates to the file name being truncated on the first space in the file name. For example sheet1.xls will zip to sheet1.zip, however, sheet 1.xls will result in sheet.zip without the file being inside.

    Can anyone point me in the right direction to resolve this issue as all the file will contain spaces with the file names.

    TIA

    Woody0135

     
    Attachments
    • Shell
      Shell
      2014-02-21

      I think you should specify the parameters for the for cycle. By default, each line of dir's output is broken into space-delimited tokens, so the spaces in the filenames are seen as separators. Try something like the following:
      for /f "tokens=*" %%A in ... "%%~nA.zip" "%%A"

       
      Attachments