Windows – Using xCopy to create entire folder structure, including root folder name and all files

batchcommand linewindowsxcopy

I looked at quite a few solutions to xCopy questions, and tried many difference
methods. (Various wildcards, paths ending in \, various xcopy switches in various combinations.)

xCopy c:\Public  d:\MyNewDir\

When done, I need the destination to include a folder called "Public" with containing all files, folders, subfolders, everything.

The result should will look like:

d:\MyNewDir\Public\(and everything inside it)

Not like this:

d:\MyNewDir\(everything inside Public)

That sounds so simple. Instead, I never see a "Public" folder created. It only creates everything WITHIN "Public"…. but never "Public" itself.
(I have many folders to copy, so I don't want to create folders individual, manually.)

Is there a solution to this simple issue using only xCopy and Windows 7?

Best Answer

I need the destination to include a folder called "Public"

containing all files, folders, subfolders, everything.

Use the following command:

xcopy c:\Public\* d:\MyNewDir\Public /s /i
  • /s - Copy folders and subfolders

  • /i - If in doubt always assume the destination is a folder e.g. when the destination does not exist.


Further Reading

Related Question