Batch file to copy folder structure

4

I want write a batch file that can copy a folder structure. This batch file would copy all folders in the source directory to the destination directory - the files themselves would not be copied.

For example, say there is a folder src with the following structure:

src
src\a\file1
src\a\file2
src\a\b\file1
src\c

The tool would create a dest folder like the following:

dest
dest\a
dets\a\b
dest\c

Is it possible to accomplish this task using a batch file?

Szere Dyeri

Posted 2009-09-25T23:56:44.353

Reputation: 144

Answers

14

Try:

XCopy "src" "dest" /T

Just make sure it's not cyclical.

To include empty directories, add /E:

XCopy "src" "dest" /T /E

Stevoni

Posted 2009-09-25T23:56:44.353

Reputation: 413

It copies files too, I only want directory structure to be copied. – Szere Dyeri – 2009-09-26T00:23:45.340

First post is corrected. – Stevoni – 2009-09-26T00:35:35.427

2You can also add the /E switch which causes empty directories to be mirrored, too. – Joey – 2009-09-26T00:44:29.947

1+1 for a solution that doesn't involve installing 3rd party programs. – RJFalconer – 2009-09-26T01:37:56.450

4

robocopy src dest /e /create

This partially achieves what you need. It will copy the directory structure and create zero length files as placeholders for the actual files. See more details here.

Nikhil

Posted 2009-09-25T23:56:44.353

Reputation: 2 347

3

not a batch file but Total Commander can do this (with a little trick):

copy a directory and use the 'Only files of this type' option. enter *.nonsense (or any other non-existent file extension) in this field.

now Total Commander will create the entire directory structure of the source folder at the destination without copying any files.

Molly7244

Posted 2009-09-25T23:56:44.353

Reputation:

1

you can just put |*.* into Total commander copy dialog and the folder structure will be copied without files

goorgle

Posted 2009-09-25T23:56:44.353

Reputation: 11

1put |. in the "only files of this type" box – Remus Rigo – 2012-08-17T19:27:17.740

1

If you just want the file structure without the zero length files then it's

robocopy src dest /e /create /xf *.*

or

robocopy src dest /mir /create /xf *.*

Woody

Posted 2009-09-25T23:56:44.353

Reputation: 11

-2

Check 47 folders app , can create & copy folders structures in visual way..

andymcgregor

Posted 2009-09-25T23:56:44.353

Reputation: 137