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?


2 Answers 2


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

  • If there are a lot of (small) files it might be a good idea to use the /Q option ("Do not display file names while copying."). At the end of the copy process it will output something like "122546 File(s) copied". Sep 24, 2018 at 11:48

1st, enumerate folder structure into a file:

dir /ad /b /s C:\ > D:\windir.txt

2nd, open D:\windir.txt in Notepad and replace all C:\ with null; save file

3rd, use for command to recurse through windir.txt to copy directory structure and files in each directory:

for /f "delims=;" %a in (D:\windir.txt) do xcopy "C:\%a" "D:\MyNewDir\%a" /c /i /g /h /k /o /x /j /b /y

You can add /q if you don't want to see the directories and files as they're being copied; I like the positive feedback.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.