Windows – How to copy entire folders/directories in command prompt

backupcmd.exerobocopywindows 8.1xcopy

My laptop isn’t booting, so I’m running a Windows ISO off a DVD and attempting to backup some files to an external hard drive plugged into the USB via Command Prompt.

With command prompt I can enter folders and copy the individual files within them to my hard drive using the robocopy command.
(E.g ‘C:\Users\Downloads robocopy E:).

However I want to copy an entire directory such as ‘C:\Program Files (x86)’ including all of the (unzipped) sub folders etc.

I’ve tried using xcopy like this:
‘C\program files (x86)\ E:\ /s /e /h /i /c /y’
& like this:
‘C:\program files (x86)\ E:\’.

But each time command prompt returns the message ‘Invalid number of parameters’.

Any idea on how I could copy these directories?

All help would be much appreciated! Thank you!

Best Answer

Here's the syntax that you need for Robocopy if you want to specify a particular source directory.

You would need to run it multiple times in order to back up multiple source folders:

robocopy /e c:\users\mguillaume\downloads "e:\laptop backup"

/e include subfolders and Empty subfolders

/s include Subfolders (but skip empty subfolders)

  • You don't want to use the /s and /e switches together; they conflict. Pick one! I personally prefer to include empty subfolders, so /e is my go-to. The way I see it, completely preserving your existing folder structure, including empty folders, may help you to organize your data in future.

  • Paths containing one or more spaces must be enclosed within double quotation marks. In your example, I noticed that your paths containing spaces were missing their quotation marks.

  • There's no need to use capital letters. Nothing here is case sensitive anyway. Feel free to use them if you want though.

Alternatively, you could copy the entire C drive and simply exclude any directories and files that you don't want. I like to use Robocopy this way, as you can back up everything you want in one shot!

That would look something like this:

robocopy /e c:\ "e:\laptop backup" /xd c:\windows c:\dell /xf c:\pagefil.sys c:\hiberfil.sys /r:0

/xd eXclude Directories

/xf eXclude Files

/r:0 run with zero Retries. I always use this so Robocopy doesn't get stuck on locked files. You will see if anything was skipped in the summary anyway.

Related Question