sdaau
sdaau

Reputation: 38619

How to copy a subfolder into a subfolder using xcopy?

Let's say I'm in C:\test directory, where I have C:\test\myHugeFolder directory and a C:\test\backup directory - and I'd like to copy myHugeFolder into backup from cmd.exe Command Prompt.

So, I thought this usage of xcopy is correct, by using relative paths:

C:\test> xcopy myHugeFolder backup\ /s /e

The thing is, xcopy here was churning for like 15 minutes, also listing each file in myHugeFolder, so I thought all was fine - then when it finished, I look into backup, and there no myHugeFolder; in fact when I search for myHugeFolder, there's only the original:

C:\test>dir myHugeFolder* /s
 Volume in drive C has no label.
 Volume Serial Number is FFFF-FFFF

 Directory of C:\test

18-10-2015  16:26    <DIR>          myHugeFolder
               0 File(s)              0 bytes

     Total Files Listed:
               0 File(s)              0 bytes
               1 Dir(s)  2.419.708.346.368 bytes free

So, obviously that is not the right command line - where am I going wrong, and what is the right invocation of xcopy to do this kind of a copy?

Upvotes: 0

Views: 532

Answers (1)

kbulgrien
kbulgrien

Reputation: 4508

The test in the question is wrong.

C:\test> dir myHugeFolder

This command will not list anything copied to the C:\test\backup folder.

A correct test is more like this:

C:\test> dir backup

It would show that the contents of C:\test\myHugeFolder was copied into C:\backup, not C:\test\backup\myHugeFolder.

If one wanted a duplicate of C:\test\myHugeFolder in C:\test\backup\myHugeFolder, one way to do that would be:

C:\test> XCOPY myHugeFolder backup\myHugeFolder /E /I

After which the following command would show the desired copy of the myHugeFolder container:

C:\test dir backup\myHugeFolder

Upvotes: 1

Related Questions