How to get a batch file to handle spaces in file n

2019-02-16 22:19发布

I am using the following batch file to make a zip file for each xml in a folder:

FOR %%f in ("C:\files\*.xml") DO 7za.exe a C:\files\zips\%%~nf.zip (%%f)

However if the file name has a space in it (test plop.xml) then the batch file does not work. It seems to split the name and thinks it is 2 files.

How to modify the batch file so that it properly handles file names with spaces?

1条回答
▲ chillily
2楼-- · 2019-02-16 22:54

Try placing quotes around the output file name.

Change

FOR %%f in ("C:\files*.xml") DO 7za.exe a C:\files\zips\%%~nf.zip (%%f)

to:

FOR %%f in ("C:\files*.xml") DO 7za.exe a "C:\files\zips\%%~nf.zip" (%%f)

May also be the variable %%f, may need to place quotes around this as well.

查看更多
登录 后发表回答