我正在尝试将批处理文件写入:
如果configFilePointerFile路径不包含空格,则以下代码有效,否则失败。
如果我在带有空格的文件路径周围添加引号(即" C:\ file paths.txt"),则会将文件路径打印到新文件,而不是将文件内容打印到新文件。
此脚本正确地将文件的内容添加到新文件中:
set configFilePointerFile=c:\filepaths.txt <-- works as long as their are no spaces.
FOR /F "delims=" %%i in (%configFilePointerFile%) DO (
type "%%i" >>newfile.txt
>> newfile.txt echo.
)
此脚本仅将文件路径添加到新文件:
set configFilePointerFile="c:\file paths.txt" <-- doesn't work with spaces in file path.
FOR /F "delims=" %%i in (%configFilePointerFile%) DO (
type "%%i" >>newfile.txt
>> newfile.txt echo.
)
有任何建议让它与包含空格的configFilePointerFile一起使用吗?
答案 0 :(得分:4)
set "configFilePointerFile=c:\file paths with spaces.txt"
FOR /F "usebackq delims=" %%i in ("%configFilePointerFile%") DO (
type "%%~i" >>newfile.txt
>> newfile.txt echo.
)