gpt4 book ai didi

windows - 如何在 Windows 中使用 xcopy 复制目录结构

转载 作者:可可西里 更新时间:2023-11-01 11:55:55 30 4
gpt4 key购买 nike

我有一个包含文件夹列表的文本文件。我的文本文件如下所示:

"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/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com