带有空格的路径名循环失败

带有空格的路径名循环失败

我在循环遍历路径名包含空格的文件时遇到问题

SET MPATH=\\server\path\some folder with space\Sample.txt
for /f %%a in ("%MPATH%") do (set file=%%~fa)
for /f "skip=1 tokens=2,160 delims=^|" %%a in (%file%) do (
echo something^|%%a^|something^|%%b^|>>"C:\Directory\temp.txt"
)

输出:

The system cannot find the file \\server\path\some.

我查看了多个帖子,建议:

  1. ..在(“\server\path\some folder with space\Sample.txt”)中执行(设置文件=%%~fa)
  2. .. in ('dir /b /s \server\path\some folder with space\Sample.txt')
  3. .. in ('输入 \server\path\some folder with space\Sample.txt')

但似乎都没有起到作用,结果是一样的:

The system cannot find the file specified.

相关内容