How to use Robocopy command parameters and usage in Powershell scripts has been explained in a detailed way with real-time examples in daily life.
This Robocopy command is used for copying the file on Windows machines, it is a very powerful command, it copies files and directories from one location to another. This robocopy command also gives on-screen a detailed report of the copy operation. Please find simple examples of how it copies one directory to another directory with detailed information.
Robocopy syntax and examples
Source E:\resumes and destination F:\eng
Robocopy E:\resumes F:\eng
This commands copies of the files which include hidden files and gives the time taken to copy these files.
Let’s discuss some switches it has got.
Robocopy switch for to copy subfolders /S
Robocopy /S E:\resumes F:\eng
Robocopy switch for to copy empty folder /E
Robocopy /S /E E:\resumes F:\eng
Robocopy Delete source files after copying to destination.
One can add /MOV switch to the command to delete files and /MOVE switch to delete both files and directories.
For moving and deleting files:
Robocopy /MOV /S /E E:\resumes F:\eng
Below example is for deleting files and directories:
Robocopy /MOVE /S /E E:\resumes F:\eng
Robocopy Modify file attributes for the copied files over the destination.
It is possible if one wants to change attributes of the copied files using the robocopy command. This affects the attributes of the files in the new location, however, the files in the source location do not get any impact that’s the beauty of this command.
Using the below example we achieve this, all files from one directory to another directory and also set the hidden attribute for all the files you can execute with ‘Robocopy’ as the syntax follows.
Robocopy /S /E /A+:H E:\resumes F:\eng
Robocopy Mirror copy a directory very powerful
Ther e is a very powerful command available Robocopy /MIR switch creates a replica of the source folder in the specified destination folder
Robocopy /MIR sourceFolderpath destinationFolderpath
This Robocopy /MIR command deletes any extra files that are present in the destination and are not present in source, makes exact replica of source folder and content.
Set same ACL access permission on the destination folder
The switch Robocopy ‘/sec’ copies all the file access permissions to the destination folder.
robocopy /sec sourceFolderpath destinationFolderpath
Please make sure you have tested these commands in lower environments before you use them in the production environment For deeper understanding and learning of this command please visit the Microsoft website.
Robocopy Switches and Use Cases
|/SEC||Copy files with security (equivalent to /COPY:DATS).|
|/COPYALL||Copy all file info (equivalent to /COPY:DATSOU).|
|/NOCOPY||Copy no file info (useful with /PURGE).|
|/SECFIX||Fix file security on all files, even skipped files.|
|/TIMFIX||Fix file times on all files, even the skipped ones.|
|/PURGE||Delete dest files/dirs that no longer exist in the source.|
|/MIR||Mirror a directory tree (equivalent to /E plus /PURGE).|
|/MOV||Move files (delete from the source after copying).|
|/MOVE||Move files and dirs (delete from the source after copying).|
|/A+:[RASHCNET]||Add the given attributes to copied files.|
|S||This switch used to Copy subdirectories, but not the empty ones.|
|/E||This switch used to Copy subdirectories, including the empty ones.|
|/LEV:n||This switch used to Only copy the top n levels of the source directory tree.|
|/Z||This switch used toCopy files in restartable mode.|
|/B||This switch used to Copy files in backup mode.|
|/ZB||This switch used for restartable mode. If access denied, use backup mode.|
|/EFSRAW||This switch used to Copy all encrypted files in EFS RAW mode.|
|/COPY:copyflag[s]||This switch for What to COPY for files (default is /COPY:DAT).|
Thank you for reading this article, if you have any questions please let us know.
Thank you for visiting my site, for any scripts in these articles you are testing please make sure you have tested this script in our lower environment before you run in production.