作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有一个包含文件夹列表的文本文件。我的文本文件如下所示:
"D:\old\FOLDER1" "D:\old\FOLDER2" "D:\old\FOLDER3" "D:\old\FOLDER4" "D:\old\FOLDER5"
all these folders have subfolders and files under it
what I want to do is use xcopy to copy FOLDER1
, FOLDER2
, FOLDER3
FOLDER4
and FOLDER5
replicate folders ,replicating the structure of those foldersso in output , I want to get
D:\output\bkup\FOLDER1\............Including all subfolders and files D:\output\bkup\FOLDER2\............Including all subfolders and files D:\output\bkup\FOLDER3\.......... Including all subfolders and files D:\output\bkup\FOLDER4\............Including all subfolders and files D:\output\bkup\FOLDER5\............ Including all subfolders and files
I have written below script which works fine for one folder
set sourceFolder="D:\old\FOLDER5"
set destinationFolder=%sourceFolder:~7,-1%
echo %destinationFolder%
xcopy /s /e /i /h /r /y %sourceFolder% "D:\output\bkup%destinationFolder%"
但由于要复制的目录数超过 100,我喜欢使用 for 循环或将要复制的目录列表传递到文本文件中,这就是我不知道如何处理的原因。
请帮助我,我不是批处理文件编写方面的专家。
最佳答案
您可以使用 for/f 逐行读取(如果需要则解析)文本文件。使用“delims=”来阅读整行。不要忘记添加引号以防止有多个参数并去除子过程中的引号
for /f "delims=" %%a in (yourtextfile.txt) do call :docopy "%%a"
goto :eof
:docopy
set sourceFolder=%~1
set destinationFolder=%sourceFolder:~7,-1%
echo %destinationFolder%
xcopy /s /e /i /h /r /y %sourceFolder% "D:\output\bkup%destinationFolder%"
goto :eof
关于windows - 如何在 Windows 中使用 xcopy 复制目录结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16877006/
我是一名优秀的程序员,十分优秀!