Robocopy
command is used on Windows to copy files and directories from one location to another. This CMD command also prints a detailed report of the copy operation. Below you can find examples for using Robocopy in various usecases.
Copy a directory
Example: Copy all the files in the directory D:\dir1\data to E:\backup\data. Don’t include sub directories or the files stored in those.
Robocopy D:\dir1\data E:\backup\data
The above command copies system files and hidden files too. Copy and Xcopy commands skip these files by default.
At the end of the command execution, it would print the summary like below.
Total Copied Skipped Mismatch FAILED Extras Dirs : 22 22 0 0 0 0 Files : 113 113 0 0 0 0 Bytes : 42.96 m 42.96 m 0 0 0 0 Times : 0:00:01 0:00:00 0:00:00 0:00:00 Speed : 83744483 Bytes/sec. Speed : 4791.897 MegaBytes/min. Ended : Wed Oct 22 22:26:14 2014
Copy directory structure
Run the below Robocopy command to copy directory structure i.e deep copy of folder hierarchy and the data in all the subfolders.
Robocopy /S D:\dir1\data E:\backup\data
This command does not copy empty directories. To copy them, you need to add /E switch.
Robocopy /S /E D:\dir1\data E:\backup\data
Delete files and directories from the source after copying
You can add /MOV switch to delete files and /MOVE switch to delete both files and directories.
For deleting files:
Robocopy /MOV /S /E D:\dir1\data E:\backup\data
For deleting files and directories:
Robocopy /MOVE /S /E D:\dir1\data E:\backup\data
Modify file attributes for the copied files
Using robocopy command we can also change attributes(system, hidden, readonly) of the copied files. This affects the attributes of the files in the new location, it does not impact the files in the source directory.
For example to copy all files from one directory to another directory and also set hidden attribute for all the files you can trigger ‘Robocopy’ with the below syntax.
Robocopy /S /E /A+:H D:\dir1\data E:\backup\data
Mirror copy a directory
Below Robocopy command creates a replica of the source folder in the specified destination folder
Robocopy /MIR sourceFolder destinationFolder
This command also deletes any extra files that are present in the destination and are not present in source.
Replicate access permission on destination folder
The option ‘/sec’ copies all the file access permissions to the destination folder also.
robocopy /sec sourceFolder destinationFolder
Note that Robocopy copies the security ACLs also to the destination only if the file has been modified. If the file has not been modified, the ACLs won’t be applied on the destination. You can check this Microsoft’s post robocopy file permissions for deeper understanding.
In Windows XP i could bring up two separate Windows Explorers boxes, one for the C drive & one for the D drive in my computer, or even one for the C drive & one for an external disk drive. I could then freely move entire directories from one drive to another with a single key press. How precisely do i do this in Windows 8.1, which so far permits me to bring up only one instance of “File Explorer.” I have only been using WIN 8.1 for a few hours, but the command prompt commands i have seen you suggest so far look primitive & like a throwback to DOS
Even in Win8, you can open multiple instances of explorer. Run ‘C:’ and ‘D:’ separately from Run, it would open C: and D: drives in two explorers. you can copy/move files with single click.
Alex, Primarily this is used as an administrator when you have a lot of folders/files to move and want to retain user permission settings. It would be a nightmare to have to move a bunch of files and then have to rebuild the permissions.
You, sound like an end user, so all you need to do is open a couple of windows and drag and drop.
Nothing wrong with DOS or MSDOS or DRDOS: modern O/S systems are BLOATWEAR
Thanks for the article: do you know if there is a way to use robocopy to copy all the files from a folder and its sub folders into a single destination folder without any of the source sub folder structure? In other words I need the destination to find all files of a file type (PDF) and COPY them all to a single folder…
You can use forfiles for this. Refer: http://www.windows-commandline.com/forfiles/
Thank You :)
Thank You so much.The information was really usefull.
how can i copy 2 types of files in one line of script? Eg, *.doc and *.xls
Robocopy Source_Folder Destination_Folder *.doc *.xls
How can I copy all only/all folders in my directory that have “DONE” in the folder name?
This is part of a backup routine and there are several hundred folders with “DONE” in the name, these are the only ones I want to copy including all the sub folders and files?
Best Regards,
I have windows 10 home edition. I used the copy command as described but I got an error message “access denied”.
I have been trying repeatedly to use normal copy command but as soon as I push enter the folder disappears.
Will the SID be affected by using ROBOCOPY to restore a server after its been renamed?
Thanks, very useful to understand robocopy !
Thanks, very useful CMD utility.
does robcopy copies: path_1\name_1 to: path_2\name_2
with either path_1 or path_2 or both are longer than 255 char ?
Presumably robcopy syntax requests path\name?
(can i omit the path if, say, i copy from current directory to current directory?)
Can someone please assist me how can move folders and files with permission from:
Suppose Drive T:\ to Drive M:\ between same domain and same server
I would like to delete all while it is moving.
Date range is prior Dec 31st 2016
Using powershell
Primarily this is used as an administrator when you have a lot of folders/files to move and want to retain user permission settings. It would be a nightmare to have to move a bunch of files and then have to rebuild the permissions.
Hello,
What if we need to copy a bunch of files(from a mapped device, to my server) and connection is poor? From time to time the connection dropped but some files have been copied successfully
I have a problem when try to copy a set of folders FROM AN “E” EXTERNAL HDD TO ANOTHER “G” HDD.
It is possible to have a problem from the letter name of G HDD?
Please help!
Adrian
using batch file commands how to store 30 student data.their academic.txt ,personal.txt,non academic.txt,result.txt in stud_details.txt.
how do i copy from my pc to googledrive online with Robocopy
setup google file stream , this will allocate your gdrave a drive letter eg G:
then do a copy c:\examplefolder\ g:\
While using robocopy /S /E \\\L$ L:\ I have encountered an issue, one of the file does not have copy permissions. Please find the error below
ERROR 5 (0x00000005) Copying File \\\L$\….
Access is denied.
Even though I have verified permissions from source the file is not getting copied nor moving ahead to the next one.
Is there an option to skip the files with access issue ? (like if error move next kind of)
Issue is same for robocopy /MIR \\\L$ L:\ command as well.
i use robocopy to copy files from source to destination, the problem is when i delete a text file from the source it will automatically removed from destination file. I want to only increment the file on the destination folder even the source file is deleted or minimized in size.
How can I copy a file from one folder to another folder with a regulated speed. e.g., the copy operation should be executed with a constant speed like 3 MB/s , 5 MB/s or 10 MB/s.
Robocopy was a nightmare, copying NTFS/Shared permissions, copying timestamps, excluding/including files ….and some problems were painful, now I use Gs Richcopy 360 and no problems and everything is smoothy