我想在所有子目录中将一个图像替换为另一个图像,但DIR(/ s)的递归功能无法识别以数字开头的文件夹。例如,它将替换目录“example / image.txt”中的文件,而不是“1234 folder / image.txt”
@ECHO off
dir /s /b image.jpg >> FileListing.txt
echo Image replaced in the following folders: >> ImageLocations.txt
for /f %%a in (FileListing.txt) do (
echo %%a >> ImageLocations.txt
xcopy /f /q "%CD%\Image.jpg" "%%a"
)
del FileListing.txt
答案 0 :(得分:1)
for /f
命令将尝试使用空格和制表符对输入行进行标记,作为标记之间的分隔符。如果您的文件/文件夹名称中包含空格,则只会检索空格前的部分。要避免它,请通过将分隔符设置为空列表来禁用行拆分
for /f "delims=" %%a in (FileListing.txt) do (
....