Truncated file name when compressing using batch file.

  • 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 "" "%%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, however, sheet 1.xls will result in 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.



    • 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 ... "" "%%A"


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks