How to copy a directory using copy or xcopy from DOS command line

Mastiff37

Distinguished
Jul 4, 2011
63
0
18,530
My windows 10 install took a dump, but I can see my files from the command line when I go there from the recovery menu. I can insert a USB drive and see it as well. All should be well, but I can't get stuff to copy. I have two examples:

At c:\Users\Bob\Desktop I have a directory called "Statements".

If I say "copy Statements e:" it won't copy the directory, but rather copies every file out of the directory to the root of e:. How can I make it copy the directory itself with its contents?

At c:\Users\Bob is my Music directory with a detailed structure for Artists/Albums/Songs. It is clearly visible as I navigate around, but no version of copy or xcopy I've found will even start. For example "copy Music e:" says "the system cannot find the file specified". xcopy says "unable to create directory e:\".

What is the trick to copying directories in dos? I come from linux where this just does what I expect the first time.
 
Solution
I just tested it myself.

With the /i switch, this xcopy command creates the destination directory automatically.

xcopy c:\test\*.* D:\newtest /e /k /q /c /i /y /h

then I tried it without the /i and it then asked me if newtest was a directory to which I said "y" and it created the folder and copied the files.

Works perfectly for me.

Dos will not copy folders,you will have to recreate the folder by copying files.
copy Statements e:
Should be
copy Statements\*.* e:\Statements ( *.* is a wildcard that select all the files)
If you enter a directory DOS will only see executables in that directory,unless you state them as environmetal commands.
Just use the whole address (like C:\Windows\System32\xcopy.exe ) either to run the copy command,or at a place where the copy command runs straight away use the whole address of the folder you want to copy.
 

Mastiff37

Distinguished
Jul 4, 2011
63
0
18,530
Well, I couldn't get it to work the way I thought it should, but I found if you make your destination directory and cd over into it, then you can use xcopy with only the source specified and it does the right thing. I'm away from my machine, but /e /s may be required to create the new directory structure underneath. Sure frustrating for a linux user.
 

Tanyac

Reputable
I just tested it myself.

With the /i switch, this xcopy command creates the destination directory automatically.

xcopy c:\test\*.* D:\newtest /e /k /q /c /i /y /h

then I tried it without the /i and it then asked me if newtest was a directory to which I said "y" and it created the folder and copied the files.

Works perfectly for me.
 
Solution

TRENDING THREADS