Windows – copy directory including ‘base’ folder

command-line-interfacecopywindowsxcopy

I need to copy folderA into folderB via the command line:

c:\temp
        \folderA
        \folderB

should become

c:\temp
         \folderA   
         \folderB\folderA

That is, exactly the same as if you copied folderA using windows explorer and pasted it into folderB.

This does not work:

xcopy /e folder1 folder2\

as you end up with the contents of folderA in folderB and not folderA itself.

Funnily enough, move does exactly what I want except that it moves instead of copy 🙂

How do you copy a folder and include the folder itself as the base folder for the copy?
I shouldn't have to use mkdir to create the target folder. (but that gets the job done nastily)

Please dont direct me to this as that does not do the above.

Update:

Thanks to the answers below using robocopy I found a solution using xcopy that doesnt prompt either:

xcopy /e /i folderA folderB\folderA

Use the /i option to avoid being asked whether the target is a directory or a file.

Best Answer

try

xcopy folder1 folder2\folder1 /e /i