How to get a batch file to handle spaces in file names?

I use the following batch file to make a zip file for each xml in the 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 ), the batch file does not work. It seems he shares the name and thinks it is 2 files.

How to change a batch file so that it correctly processes filenames with spaces?

+8
filenames batch-file
source share
1 answer

Try putting quotation marks around the output file name.

Edit

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

in

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

It may also be a %% f variable, you may also need to place quotation marks around it.

+14
source share

All Articles