我有一个文本文件,其中包含我需要上传的文件的文件路径,例如:
F:\文件夹\子\ file.ext
我能够找到一个将所有文件放入目标文件夹的脚本,但我似乎无法对其进行修改以将其包装在其包含的文件夹中。我尝试了脚本I found here,但它似乎没有工作或抛出任何错误,而且我太绿了,无法花费数小时自学。希望有人可以帮我修改我用过的脚本
@Echo Off
cls
set dest=C:\filestoupload
set i=1
for /f %%f in (imfcheckmassaged.txt) do (
for /f "tokens=*" %%F in ('dir /S /B /A:-D "%%f"') Do (
xcopy /S/E "%%F" "%dest%"
)
)
答案 0 :(得分:0)
@Echo Off
cls
set "dest=C:\filestoupload"
set "i=1"
rem take all non-empty lines from file `imfcheckmassaged.txt`
rem for instance `F:\Folder\Sub\file.ext`
for /f "tokens=*" %%f in (imfcheckmassaged.txt) do (
rem find `file.ext` in the folder `F:\Folder\Sub\`
rem (and all occurrences in its subdirectories, note /S switch)
rem for instance `F:\Folder\Sub\file.ext`
rem and `F:\Folder\Sub\Sub2\file.ext`
rem and `F:\Folder\Sub\Sub2\Sub3\file.ext`
for /f "tokens=*" %%F in ('dir /S /B /A:-D "%%~f" 2^>NUL') Do (
rem copy them into the ˙%dest%˙ folder including folder structure
xcopy "%%~F" "%dest%\%~pF"
)
)
以上代码段将导致以下(完整路径)文件结构
(根据rem
评论中给出的例子):
C:\filestoupload\Folder\Sub\file.ext
C:\filestoupload\Folder\Sub\Sub2\file.ext
C:\filestoupload\Folder\Sub\Sub2\Sub3\file.ext
资源(必读):
%~f
,%~pF
等特殊页面)Command Line arguments (Parameters) 2>NUL
等特殊页面)Redirection "
双引号,^
插入符号等。)Escape Characters, Delimiters and Quotes