-1

All Xcopy/robocopy documentation seems to gloss over copying the folder as if you are performing a right-click copy and paste.

I want C:\Folder to copy to D:\Whatever but I want it to look like D:\Whatever\Folder

I dont understand why all commands only focus on whats beneath the specified folder. I also cannot simply set my source as C:\ since there are other folders that I do not want to copy. What command would best execute what im looking for?

Thanks

Clint Siebert
  • 11
  • 1
  • 1
  • 2
    ```@%SystemRoot%\System32\xcopy.exe "C:\Folder" "D:\Whatever\Folder\" /Options```; ```@%SystemRoot%\System32\Robocopy.exe "C:\Folder" "D:\Whatever\Folder" /Options```. – Compo Apr 28 '22 at 16:47
  • I am really astonished to read that you did not have the idea to put the name of the source folder also at end of the destination folder. `%SystemRoot%\System32\xcopy.exe` creates always the entire destination directory tree on destination argument string ending with a backslash to make it 100% clear for `xcopy` that the destination is a directory name and not a file name. Just the destination drive must exist on starting `xcopy`. – Mofi Apr 28 '22 at 17:09
  • `%SystemRoot%\System32\robocopy.exe` has a special argument string parsing. It interprets ``\`` left to one more ``\`` or left to `"` as an escape character and so interprets the following backslash or double quote as part of the source/destination directory path. For that reason make always sure that the source/destination path on being enclosed in `"` does either end with `Folder Name"` or with `Folder Name\\"`, but never with `Folder Name\"`. If the source or the destination is the root directory of a drive on which the path must end with a backslash, don't use double quotes. – Mofi Apr 28 '22 at 17:14

2 Answers2

0
xcopy /s /e "C:\Folder" "D:\Whatever\Folder\"

Should create d:\whatever\Folder if it doesn't already exist, then copy c:\folder files there, and carry on to the subdirectories and create those subdirectories with their files below d:\whatever\Folder

Magoo
  • 77,302
  • 8
  • 62
  • 84
  • 1
    This does not work, it copies C:\Folder\SUBFOLDERS to D:\Whatever\SUBFOLDERS. I want C:\Folder to go to D:\Whatever\ – Clint Siebert Apr 28 '22 at 17:55
  • @OP: You say ` I want it to look like D:\Whatever\Folder`. Seems you want the files (only) in `c:\folder` to be copied to `d:\whatever`. That's `xcopy "C:\folder\*" "D:\whatever\". If `d:\whatever` already exists, `COPY "c:\folder* "D:\whatever"` would copy the files only,t oo. "`xcopy` comes from an era when right-copying was a futuristic concept; it was intended to bulk-copy from a tree since `copy` could do the simply copy from a directory, hence the emphasis on subdirectories. – Magoo Apr 28 '22 at 18:29
  • @Magoo so how do I copy the C:\Folder as if I was performing a right click copy and performing a right click paste to C:\Whatever\ – Clint Siebert Apr 28 '22 at 18:52
0

By specifying the expected folder name in the destination it works as I wanted. my command was xcopy C:\Folder D:\Whatever\Folder /S /I /W .

Clint Siebert
  • 11
  • 1
  • 1