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.

1

Try Powershell's Copy-item:

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

OR

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

| improve this answer | |
  • The Linux cp command also functions as an alias for copy-item. – Davidw Aug 13 '13 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

| improve this answer | |
  • 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 '13 at 4:21
  • Not that I know of from cmd - for reference copy xcopy robocopy – 50-3 Aug 13 '13 at 4:31
  • Powershell does. – Davidw Aug 13 '13 at 4:32
  • David beat me to it Copy-Item c:\DirA c:\DirB -recurse – 50-3 Aug 13 '13 at 4:37
  • Ah, I just posted that as an answer. – Davidw Aug 13 '13 at 4:38

Your Answer

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

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