您好,我在 Batch FOR 中的 %%a 属性中遇到了空格问题。
如果文件夹中有一些文件
yoda jedi.tif
jaba king.tif
solo smug.tif
以下代码,
@echo off & setlocal
for /f %%a IN ('dir /b /s "R:\Scans\Epson_v550\*.tif"') do (
echo This was received: %%a
)
输出结果为:
This was received: yoda
This was received: jaba
This was received: solo
我如何重构它以便 %%a 包含来自 %%a 的空格的完整文件名?
我喜欢这个结果:
This was received: yoda jedi.tif
This was received: jaba king.tif
This was received: solo smug.tif
但即使我尝试,
echo This was received: "%%a"
我仍然只找回了空格前的单词。就像 %%a 在分配期间在第一个空格处被砍掉了一样。请帮忙?
答案1
我想我已经明白了,添加“delims=”这一行似乎已经解决了文件名中的空格问题。
@echo off & setlocal
for /f "delims=" %%a IN ('dir /b /s "R:\Scans\Epson_v550\*.tif"') do (
echo This was received: %%a
)
这按预期工作,结果是:
This was received: yoda jedi.tif
This was received: jaba king.tif
This was received: solo smug.tif
如果
yoda jedi.tif
jaba king.tif
solo smug.tif
存在于指定文件夹中。