2

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.

wal
  • 147
  • 3
  • 12

3 Answers3

4

try

xcopy folder1 folder2\folder1 /e /i
Laurentiu Roescu
  • 2,246
  • 16
  • 17
1

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.

John Gardeniers
  • 27,262
  • 12
  • 53
  • 108
0

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.)

HopelessN00b
  • 53,385
  • 32
  • 133
  • 208
  • 1
    that doesnt work did you even try it? does exactly the same as xcopy command above, folderA is *not* copied. – wal Aug 06 '12 at 03:55