如何复制树文件夹,但只保留每个文件夹名为“dist”的文件夹?

时间:2015-07-01 09:13:28

标签: windows batch-file cmd copy

如何使用 Windows cmd (或bat文件)复制具有以下结构的文件夹树:
源/文件夹1 / dist
源/文件夹1 /其他文件..(多个)
源/文件夹2 / dist
源/文件夹2 /其他文件..(多个) ...

事情是我只想保留每个“文件夹#”中的dist文件夹,例如最终形式为:
目的地/文件夹1 / dist
目的地/文件夹2 / dist

谢谢! UKW。

1 个答案:

答案 0 :(得分:3)

从命令行使用

for /d %a in ("x:\source\*") do xcopy /s /e /y /i "%~fa\dist" "x:\destination\%~nxa\dist"

要在批处理文件中使用,for可替换参数中的百分号需要加倍

for /d %%a in ("x:\source\*") do xcopy /s /e /y /i "%%~fa\dist" "x:\destination\%%~nxa\dist"
相关问题