简体   繁体   中英

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. 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.).

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 is NOT a third party command, there's no need for software. It was added back in 1986 (MS-DOS 3.30, correct me if I'm wrong), so every Windows OS has it.

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

Which will:

  • Copy all directories structure, including empty directories ( /e )
  • It won't prompt for confirmation
  • Hidden files will be also copied.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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