I don't know how to name this behavior vividly, just call it loyalcopy.
Two figures will illustrate it clearly.
I'd like to issue two commands to copy two filesystem nodes (regardless it is a file for a directory):
loyalcopy c:\libsrc\include d:\temp\dest
loyalcopy c:\libsrc\mm_psfunc.h d:\temp\destand see result like this:
What actual Windows commands can achieve this effect? I tried xcopy and robocopy, and they do not work as desired. For example, xcopy c:\libsrc\include d:\temp\dest /s would copy contents inside include, not creating a mirrored include directory in destination folder.
On Unix, I know I can replace loyalcopy with cp -r to achieve desired result. But is there Windows equivalent of it? Better to have Windows stock commands, no third-party software involved.
2 Answers
Just run cp -r c:\libsrc\include d:\temp\dest in PowerShell. It'll work as expected. It's actually the alias to
Copy-Item -Recurse c:\libsrc\include d:\temp\destWith xcopy or robocopy you'll need to specify the folder name in the destination in order for it to be created
robocopy /E c:\libsrc\include d:\temp\dest\includexcopy /E /I /H c:\libsrc\include d:\temp\dest\include
/I:If Source is a directory or contains wildcards and Destination does not exist,xcopyassumes Destination specifies a directory name and creates a new directory. Then,xcopycopies all specified files into the new directory. By default,xcopyprompts you to specify whether Destination is a file or a directory.
To get help on any classic Windows tools just use /?, for example xcopy /?, robocopy /?. Note that xcopy has been deprecated and may be removed in the future
Try this:
xcopy /h /e /i "c:\libsrc\include\" "d:\temp\dest\include\"
xcopy /h /e /i "c:\libsrc\mm_psfunc.h" "d:\temp\dest\mm_psfunc.h" 3