Is there Windows copy command that mimic Unix `cp -r` behavior?

I don't know how to name this behavior vividly, just call it loyalcopy.

Two figures will illustrate it clearly.

before copy

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\dest

and see result like this:

after copy

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\dest

With 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, xcopy assumes Destination specifies a directory name and creates a new directory. Then, xcopy copies all specified files into the new directory. By default, xcopy prompts 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

1

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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like