[英]copy a whole folder (not just contents) into another folder in cmd terminal
I would like to copy an entire folder to other folder. 我想将整个文件夹复制到其他文件夹。 NOT JUST the content of that folder.
不仅仅是该文件夹的内容。
For that I would like to do it in the CMD terminal. 为此,我想在CMD终端中进行。
FolderOriging1 FolderOriging1
/---folderA
/---folderB
/---folderC
FolderDesteny FolderDesteny
/---empty
Result that I like: 结果我喜欢:
FolderDesteny
/---folderA
(with folderA
including all the files and folders and subfolders) (包含
folderA
包括所有文件和文件夹以及子文件夹)
I saw several posts here & here for instance 我在这里和这里看过几个帖子
They all end up copying the contents of folder A, but not the folder itself. 它们最终都会复制文件夹A的内容,但不会复制文件夹本身。
for instance: 例如:
xcopy C:\folderA C:\folderB /E
this copies the contents of folder A to folder B 这会将文件夹A的内容复制到文件夹B.
xcopy C:\folderA C:\folderB\folderA /E
Does not work neither 不起作用
Other modifiers like the one pointed out in the above posted link do not work neither: 上面发布的链接中指出的其他修饰符也不起作用:
xcopy C:\folderA C:\folderB /E /i
The reason xcopy C:\\folderA C:\\folderB\\folderA /E
does not work is because folderA
does not exist in C:\\folderB
. xcopy C:\\folderA C:\\folderB\\folderA /E
不起作用的原因是因为在C:\\folderB
中不存在folderA
。 Which is evident from the directory structure in your question: 从您的问题中的目录结构可以看出这一点:
/folderA
/folderB
/folderC
You need to use the /I
switch to create the directory if it does not exist. 如果目录不存在,则需要使用
/I
开关创建目录。 So your command should be: 所以你的命令应该是:
xcopy C:\folderA C:\folderB\folderA /E /I
Note that Microsoft also advises to use the /O
, /X
, /H
and /K
switches with xcopy
when you want to retain the folder's permissions. 请注意,当您要保留文件夹的权限时,Microsoft还建议将
/O
, /X
, /H
和/K
开关与xcopy
配合使用。 There effects follow: 效果如下:
/H - Copies hidden and system files also.
/K - Copies attributes. Typically, Xcopy resets read-only attributes.
/O - Copies file ownership and ACL information.
/X - Copies file audit settings (implies /O)
Source: HOW TO: Copy a Folder to Another Folder and Retain its Permissions 来源: 如何:将文件夹复制到另一个文件夹并保留其权限
If you would like more information about copying a folder and its contents to another folder using xcopy
and alternatives to using xcopy
, then check out this Super User question: Commmand line command to copy entire directory (including directory folder) to another directory . 如果您想了解复制文件夹及其内容使用其他文件夹的详细信息
xcopy
和替代使用xcopy
,然后看看这个超级用户的问题: 条命令行命令复制整个目录(包括目录文件夹)到另一个目录 。
Try this: 尝试这个:
echo d|xcopy /E "c:\folderA" "C:\folderB\folderA"
The d
will serves as the interactive choice d
for folder. 该
d
将作为互动选择d
的文件夹中。
Or just 要不就
xcopy /E "c:\folderA" "C:\folderB\folderA\"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.