简体   繁体   English

如何使用批处理脚本复制文件和文件结构

[英]How to copy files and file structure with a batch script

I am writing a batch script that does a myriad of things.我正在编写一个批处理脚本来做很多事情。 The one part I am stuck on is copying files/file structure from a location to my final image.我坚持的一个部分是将文件/文件结构从一个位置复制到我的最终图像。 The file structure looks something like this文件结构看起来像这样

Foo
|->Bar
|  |->Snafu
|  | |-><FILES>
|  |-><FILES>
|->Bar2
|  |->Snafu
|  | |-><FILES>
|  |-><FILES>
|->Bar3
|  |->Snafu
|  | |-><FILES>
|  |-><FILES>
etc...

I want to copy the whole contents of the Folder Foo while maintaining the file structure.我想在保持文件结构的同时复制文件夹 Foo 的全部内容。 Here is the rub...this has to be able to run on a clean copy of Windows, so I cannot use any third party programs (which leaves out XCOPY, etc.).问题来了……这必须能够在 Windows 的干净副本上运行,所以我不能使用任何第三方程序(不包括 XCOPY 等)。

I have tried using the "copy" command with various parameters, but the closest I get is getting the files with no folder structure.我曾尝试使用带有各种参数的“复制”命令,但我得到的最接近的是获取没有文件夹结构的文件。 I am not always sure what is in the folders, so I can't even hard code it.我并不总是确定文件夹中有什么,所以我什至无法对其进行硬编码。

I would appreciate any help.我将不胜感激任何帮助。 Thanks!谢谢!

You can use XCOPY, which is way better than COPY.您可以使用 XCOPY,它比 COPY 好得多。

XCOPY is NOT a third party command, there's no need for software. XCOPY 不是第三方命令,不需要软件。 It was added back in 1986 (MS-DOS 3.30, correct me if I'm wrong), so every Windows OS has it.它是在 1986 年添加的(MS-DOS 3.30,如果我错了,请纠正我),所以每个 Windows 操作系统都有它。

Command would be: xcopy /y /h /i /e foo bar命令是: xcopy /y /h /i /e foo bar

Which will:这将:

  • Copy all directories structure, including empty directories ( /e )复制所有目录结构,包括空目录( /e
  • It won't prompt for confirmation它不会提示确认
  • Hidden files will be also copied.隐藏文件也将被复制。

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

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