批量提取名称中带有空格的rar
我正在尝试批量提取某些目录中某些 zip 中的一些 rar。 长话短说,这是我对 rar 文件的循环:
for %%r in (*.rar) do (
unrar x %%r
)
问题是 %%r 得到了错误的值。 如果文件名是“file name.rar”,则 %%r 获取值“file” - 它停在文件名中的第一个空格处。
如何让这个循环处理名称中带有空格的文件?
谢谢
I am trying to batch extract some rar's that are in some zip in some directories. Long story short this is my loop through the rar files:
for %%r in (*.rar) do (
unrar x %%r
)
Problem is that %%r gets the wrong value. If the files name is "file name.rar" then %%r gets the value "file" - it stops at the first space in the file name.
How do I get this loop to work file files with spaces in names?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
试试这个:
如果您在批处理文件中使用它,请记住您需要将百分号加倍才能转义它们。
Try this:
If you are using it in a batch file, remember you will need to double the percent signs to escape them.
%%r
将包含完整的文件名(包括空格)。 这是您对unrar
的调用出现问题的。 如果文件名包含空格,则必须将其用引号括起来,否则unrar
将无法看到两个(空格分隔的)参数file
和 < code>name.rar 实际上是带有空格的单个文件名。因此,以下内容将起作用:
另外,如果您好奇问题出在哪里,有时只需用 echo: 替换程序调用会非常有帮助,
您将看到 %%r 在文件名中包含空格并且不会删除它们分开。
%%r
will contain the complete file name including spaces. It's your call tounrar
which has the problem. If the file name contains spaces you have to enclose it in quotation marks, otherwiseunrar
won't be able to see that the two (space-separated) parametersfile
andname.rar
are actually a single filename with a space.So the following will work:
Also, if you aer curious where the problem lies, it's sometimes very helpful to simply replace the program call with echo:
where you will see that %%r includes the spaces in file names and doesn't rip them apart.
问题是“for”使用空格作为默认分隔符。 您可以使用 delims = xxx 进行设置。 请查看此处了解语法。 或者您可以使用 ForFiles。
The problem is that 'for' uses space as the default delimited. You can set this using the delims = xxx. look here for syntax. Or you can use ForFiles.