如何获取批处理文件来处理文件名中的空格? [英] How to get a batch file to handle spaces in file names?

查看:228
本文介绍了如何获取批处理文件来处理文件名中的空格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下批处理文件为文件夹中的每个xml制作一个zip文件:

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)

但是,如果文件名中有空格(test plop.xml),则批处理文件将不起作用.似乎已拆分名称,并认为它是2个文件.

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?

推荐答案

尝试在输出文件名周围加上引号.

Try placing quotes around the output file name.

更改

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

收件人:

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

也可能是变量%% f,也可能需要在引号周围加上引号.

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

这篇关于如何获取批处理文件来处理文件名中的空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆