批量提取名称中带有空格的rar

发布于 2024-07-18 08:13:12 字数 252 浏览 8 评论 0原文

我正在尝试批量提取某些目录中某些 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

赠意 2024-07-25 08:13:12

试试这个:

for /f "usebackq delims==" %i in (`dir /b *.rar`) do unrar x "%i"

如果您在批处理文件中使用它,请记住您需要将百分号加倍才能转义它们。

Try this:

for /f "usebackq delims==" %i in (`dir /b *.rar`) do unrar x "%i"

If you are using it in a batch file, remember you will need to double the percent signs to escape them.

ま昔日黯然 2024-07-25 08:13:12

%%r 将包含完整的文件名(包括空格)。 这是您对 unrar 的调用出现问题的。 如果文件名包含空格,则必须将其用引号括起来,否则 unrar 将无法看到两个(空格分隔的)参数 file 和 < code>name.rar 实际上是带有空格的单个文件名。

因此,以下内容将起作用:

for %%r in (*.rar) do unrar "%%r"

另外,如果您好奇问题出在哪里,有时只需用 echo: 替换程序调用会非常有帮助,

for %%r in (*.rar) do @echo %%r

您将看到 %%r 在文件名中包含空格并且不会删除它们分开。

%%r will contain the complete file name including spaces. It's your call to unrar which has the problem. If the file name contains spaces you have to enclose it in quotation marks, otherwise unrar won't be able to see that the two (space-separated) parameters file and name.rar are actually a single filename with a space.

So the following will work:

for %%r in (*.rar) do unrar "%%r"

Also, if you aer curious where the problem lies, it's sometimes very helpful to simply replace the program call with echo:

for %%r in (*.rar) do @echo %%r

where you will see that %%r includes the spaces in file names and doesn't rip them apart.

初与友歌 2024-07-25 08:13:12

问题是“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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文