Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

3 Answers

up vote 1 down vote accepted

try

xcopy folder1 folder2\folder1 /e /i
share|improve this answer
add comment

robocopy \folderA \folderB\folderA /s will create folderA at the destination and perform a recursive copy. Check what other options you may want or require. e.g. /e if you want to include empty folders.

share|improve this answer
add comment

Robocopy.

If I understand the parameters correctly, you'd want to do Robocopy C:\temp\folderA C:\temp\folderB /COPYALL /E /DCOPY:T

(Copy folder A into location B, preserve all attributes and ACLs, include all subfolders even empty ones, preserve directory timestamps.)

share|improve this answer
1  
that doesnt work did you even try it? does exactly the same as xcopy command above, folderA is not copied. –  wal Aug 6 '12 at 3:55
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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