简体   繁体   English

使用xcopy / robocopy复制目录

[英]Copy a directory with xcopy/robocopy

I have a batch script which takes a directory path as parameter. 我有一个批处理脚本,它将目录路径作为参数。 Inside the script, I'd like to copy this directory somewhere else. 在脚本中,我想将此目录复制到其他位置。

For example, let the script parameter be "C:\\Users\\Raffaele\\Foo" and the copy destination be "C:\\Foe". 例如,让脚本参数为“ C:\\ Users \\ Raffaele \\ Foo”,复制目标为“ C:\\ Foe”。 At the end, I'd like to have "C:\\Foe\\Foo". 最后,我想使用“ C:\\ Foe \\ Foo”。 Instead, the best I can get (both using xcopy and robocopy) is all files and subdirectories inside "Foo" copied into "Foe". 相反,我能得到的最好的方法(使用xcopy和robocopy)都是将“ Foo”内的所有文件和子目录复制到“ Foe”中。

xcopy is good enough for your requirements, read HELP XCOPY and HELP CALL and try xcopy足以满足您的要求,请阅读“ HELP XCOPY和“ HELP CALL然后尝试

call :docopy c:\users\rafaele\foo c:\foe
goto :eof
:docopy
xcopy /S /E /I %1 %2\%~n1
goto :eof

the trick is to extract the directory name and use it to specify both source and destination directories 技巧是提取目录名称并使用它来指定源目录和目标目录

the /S flag copies the directories inside source /S标志复制源内部的目录

the /E flag creates directories in destination if they exist but are empty in source /E标志在目标中创建目录(如果目录存在但在源目录中为空)

the /I flag assumes the destination is a directory and creates it /I标志假定目标是目录并创建它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM