简体   繁体   English

复制目录并创建上层目录结构

[英]Copy directory and create upper directory structure

In windows (desktop, a batch file, xcopy, robocopy) is there a way to copy a directory and have the structure above it created on the destination? 在Windows(桌面,批处理文件,xcopy,robocopy)中,是否可以复制目录并在目标位置创建其上方的结构?

For example, say I have a directory of files at c:\\data\\outlook\\profiles\\2013. 例如,假设我在c:\\ data \\ outlook \\ profiles \\ 2013下有一个文件目录。

I want to copy the 2013 directory to c:\\copy but want it to look like this: c:\\copy\\data\\outlook\\profiles\\2013. 我想将2013目录复制到c:\\ copy,但希望它看起来像这样:c:\\ copy \\ data \\ outlook \\ profiles \\ 2013。

Of course, I can manually create the structure before the copy, but I am looking to do this in bulk. 当然,我可以在复制之前手动创建结构,但是我希望进行批量创建。

Here is a routine that should copy the target with its full path. 这是一个例程,应复制目标及其完整路径。

@echo off
call :CopyWithPath "C:\Data\Outlook\Profiles\2013" "C:\Copy"
exit /b %ErrorLevel%

:CopyWithPath <Source> <Target>
md "%~f2\%~p1" && copy "%~f1" "%~f2\%~p1"
exit /b %ErrorLevel%

Example of the command with values 带值的命令示例

md "C:\Copy\Data\Outlook\Profiles\" && copy "C:\Data\Outlook\Profiles\2013" "C:\Copy\Data\Outlook\Profiles\"

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

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