1

I want to copy the directory itself, not only the contents.

For example I have

C:\DirA\SubDirA\FileA

I want to copy DirA into DirB so that I have

C:\DirB\DirA\SubDirA\FileA

Here's what I've tried

copy C:\DirA C:\DirB
xcopy C:\DirA C:\DirB /e /s

But whatever I try to do, DirA gets left out

C:\DirB\SubDirA\FileA

Note: I have a list of directories I want to copy, so I don't know the directory name beforehand and I can't afford to run a heavyweight program like robocopy 1,000 times.

2 Answers 2

1

Try Powershell's Copy-item:

copy-item C:\DirA -Destination C:\DirB -Recurse

OR

cp C:\DirA -Destination C:\DirB -Recurse

1
  • The Linux cp command also functions as an alias for copy-item.
    – Davidw
    Aug 13, 2013 at 4:41
0

Easiest way would be:

xcopy C:\DirA\* C:\DirB\DirA /e /s

Or say your had the folder set as var %foo% in a batch for script

xcopy C:\%foo%\* C:\DirB\%foo%\ /e /s

EDIT:

Also if you are happy to use powershell over Command Prompt

Copy-Item c:\DirA c:\DirB -recurse

8
  • So I have to explicitly specify the source root folder name in the target path as well? Does Windows not have an equivalent to linux's copy -R /mypath /another_existing_path ?
    – David
    Aug 13, 2013 at 4:21
  • Not that I know of from cmd - for reference copy xcopy robocopy
    – 50-3
    Aug 13, 2013 at 4:31
  • Powershell does.
    – Davidw
    Aug 13, 2013 at 4:32
  • David beat me to it Copy-Item c:\DirA c:\DirB -recurse
    – 50-3
    Aug 13, 2013 at 4:37
  • Ah, I just posted that as an answer.
    – Davidw
    Aug 13, 2013 at 4:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .