Javatpoint Logo
Javatpoint Logo

What is the robocopy command to copy folders and subfolders?

A reliable file copy command for the Windows command line is called robocopy. It enables users to move disks, folders, and files across different locations.

Robocopy hasn't undergone many alterations in the 25 years since it was first included in the Windows NT4 resource pack. However, the SMB compression is one of the new features but the usage remains the same. Robocopy is one of the greatest free applications for file copy/mirror operations since it has many amazing capabilities, such as the capacity to copy NTFS ACLs (permissions).

What is the robocopy command to copy folders and subfolders

For the following Microsoft operating systems, robocopy.exe is a third-party command that can be used.

  • NT in Windows (In resource kit)
  • MS Windows 2000 (In resource kit)
  • Operating System 2008
  • OS Windows Vista
  • OS Window 7
  • OS Window 8
  • OS Window 10
  • OS Windows 10

The syntax for Windows 10 and 11:

ROBOCOPY source destination [file [file]...] [options]

  • Source :

Source directory (server share path or drive: path).

  • Destination :

It is a desired dictionary (Drive: path or Server Share Path).

  • File :

(Names/wildcards: the default is "*.*") File(s) to copy.

Copy options:

  • /S :

Subdirectories should be copied, but not empty ones.

  • /E :

It is used to copy subdirectories, even empty ones.

  • /LEV:n :

The source directory tree should only be copied up to n levels.

  • /Z :

In restartable mode, copy files.

  • /B :

Make backup copies of your files.

  • /ZB :

Switch to restartable mode. When access is refused, go to backup mode.

  • /J :

Using unbuffered I/O copy (recommended for large files).

  • /EFSRAW :

In EFS RAW mode, copy all encrypted files.

  • /COPY:[copyflags] :

(/COPY: DAT is the default) What to COPY for files.

(Copyflags: Data (D), Attributes (A), and Timestamps (T)).

O = Owner information, U= aUditing information, S = Security=NTFS ACLs.

  • /SEC :

Secure file copying is comparable to /COPY: DATS.

  • /COPYALL:

It is used to copy all file information (corresponding to /COPY: DATSOU).

  • /NOCOPY :

No file information is copied (helpful with /PURGE).

  • /SECFIX :

Improve file security for all files, even those that were skipped.

  • /TIMFIX :

The file time for all files should be fixed, including skipped files.

  • /PURGE:

If the destination files or directories are gone from the source, delete them.

  • /MIR:

/E plus /PURGE are the equivalent of mirroring a directory tree.

  • /MOV:

Files should be moved (deleted from the source after copying).

  • /MOVE:

Files and directories should be moved (deleted from the source after copying).

  • /A+:[RASHCNET]:

It is used to add the specified properties to copy files.

  • /A-:[RASHCNET] :

It is used to take the specified properties out of duplicated files.

  • /CREATE :

It is used to create directory trees and files with zero length.

  • /FAT:

It is used to generate the final files utilizing only 8.3 FAT file names.

  • /256 :

It disables the support for very long paths (more than 256 characters).

  • /MON:n:

Keep an eye on the source; rerun when more than n changes are visible.

  • /MOT:m :

Watch the source; if anything changes, run it again in m minutes.

  • /RH:hhmm-hhmm :

Run hours are the window of time within which fresh copies may be started.

  • /PF :

It is used to check the run hours for each file, rather than for each pass.

  • /IPG:n :

The inter-packet gap (ms), which releases bandwidth on slow lines.

  • /SJ :

Junctions should be copied as junctions rather than as the junction targets.

  • /MT[:n] :

Use n threads to perform multi-threaded copying (default 8). At least one and no more than 128 must be entered as n. The /IPG and /EFSRAW options do not work together with this option. You can redirect output using the /LOG option for improved performance.

  • /DCOPY:[copyflags] :

The default value for what to copy for directories is /DCOPY: DA. (Copyflags: Data, Attributes, Timestamps, EAs, and Skip alternative Data Streams).

  • /NODCOPY :

No directory information is copied (the default /DCOPY: DA is complete).

  • /NOOFFLOAD :

Without utilizing the Windows Copy Offload technique, copy files.

  • /COMPRESS:

If appropriate, request network compression while transferring files.

Options for Copy File Throttling :

  • /IoMaxSize:n[KMG] :

n [KMG] bytes is the requested maximum I/O size per read/write cycle.

  • /IoRate:n[KMG] :

The number of [KMG] bytes per second for the requested I/O rate.

  • /Threshold:n[KMG] :

n [KMG] bytes is the file size threshold for throttling (see Remarks).

Choices for file selection :

  • /A :

Just the files with the archive property set should be copied.

  • /M :

Reset the property and copy just the files that have it set to "archive".

  • /IA:[RASHCNETO]:

Do not include any files unless at least one of the following characteristics is specified.

  • /XA:[RASHCNETO] :

A file will be excluded if any of the above properties are set.

  • /XF file [file]... :

Files with the provided names, paths, or wildcards will be excluded.

  • /XD dirs [dirs]... :

Folders with the specified names or paths will be excluded.

  • /XC :

It excludes files that have been modified.

  • /XN :

It excludes more recent files.

  • /XO :

Older files should be excluded.

  • /XX :

It excludes supplementary folders and files.

  • /XL :

Leave out any lone files and directories.

  • /IS :

It comprises the same files.

  • /IT :

Modified files should be included.

  • /MAX:n :

Files more than n bytes will be ignored as the maximum file size.

  • /MIN:n :

It excludes files with a size of n bytes or less.

  • /MAXAGE:n :

The files older than n days/date are excluded due to a maximum file age.

  • /MINAGE:n :

It excludes files that are less than n days/date old as a minimum.

  • /MAXLAD:n :

The files with a maximum last access date of n are excluded.

  • /MINLAD:n :

Exclude files used after n days from the minimum last access date. (If n 1900, n is equal to the number of days; else, n is the date, in the format YYYYMMDD).

  • /FFT :

Think of FAT file timings (2-second granularity).

  • /DST :

Make up for DST time variations by one hour.

  • /XJ :

It excludes junction points and symbolic links (both for files and folders).

  • /XJD :

Directories and junction points should not have symbolic connections.

  • /XJF :

File symbolic links should be excluded.

  • /IM :

It contains updated files (differing change times).

Retry options :

  • /R:n :

Retries per failed copy are set to 1,000,000 by default.

  • /W:n :

There is a 30-second waiting period between trials by default.

  • /REG :

It is used to save the default values for /R:n and /W:n in the registry.

  • /TBD :

It is used to hold off until share names are specified (retry error 67).

  • /LFSM :

It is used to the copy pause and resume feature while operating in low free space mode (see Remarks).

  • /LFSM:n[KMG] :

The floor size in n [K: kilo, M: mega, G:giga] bytes, and the /LFSM command.

Logging options :

  • /L :

Do not copy, timestamp, or remove any files; just list them.

  • /X :

Not just the chosen ones but any additional files as well.

  • /V:

It is used to create output that is verbose, and displays skipped files.

  • /TS :

Timestamps from the source file should be included in the result.

  • /FP :

It includes file names with their full paths in the output.

  • /BYTES :

It displays sizes in bytes.

  • /NS :

Do not log file sizes if there is no size.

  • /NC :

Do not log file classes if there is no class.

  • /NFL :

Do not log file names or a file list.

  • /NDL :

Do not log directory names; do not provide a directory list.

  • /NP :

Do not show the copied % if there is no progress.

  • /ETA :

It displays the copied files' predicted time of arrival.

  • /LOG: file :

The LOG file as the status output (overwrite existing log).

  • /LOG+:file :

The LOG file as the status output (append to existing log).

  • /UNILOG: file :

It creates a UNICODE log file as the output status (overwrite existing log).

  • /UNILOG+:file :

It creates a UNICODE log file as the output status (append to existing log).

  • /TEE :

It creates a log file and output it to a console window.

  • /NJH :

Not a job header.

  • /NJS :

There is no position description.

  • /UNICODE :

It is used to show the output in the UNICODE format.

Job options:

  • /JOB: jobname :

The named job file's parameters should be used.

  • /SAVE jobname :

It is used to the specified job file, save the parameters.

  • /QUIT :

The command line has been processed, exit (to view parameters).

  • /NOSD :

There is no source directory mentioned.

  • /NODD :

There is no designated destination directory.

  • /IF :

Add the files listed below.

Formerly, using /PURGE or /MIR on the volume's root directory made robocopy perform the specified operation to files inside the System Volume Information directory as well. It is no longer true. If /PURGE or /MIR is supplied, robocopy skips any files or directories with those names in the top-level source and destination directories of the copy session.

The classification of modified files only applies when the source and destination filesystems (such as NTFS) support change timestamps and the source and destination files have different change timings. By default, some files are not copied; enter /IM to include them.

The/DCOPY: E flag demands extended attribute copying for directories. It should be noted that robocopy currently keeps on even if the EAs for a directory cannot be duplicated. /COPYALL does not contain this flag either.

Robocopy is asked to run in "low free space mode" by using the /LFSM command-line option. While in that mode, file copying would suspend robocopy anytime the destination volume's free space would drop below a predetermined "floor" value, which can be explicitly defined by the LFSM:n[KMG] variant of the flag. Ten percent of the size of the destination volume is used as the floor if /LFSM is supplied without a floor value. The commands /MT, /EFSRAW, /B, and /ZB do not work in low free space mode.

The syntax for Windows 8 and earlier :

ROBOCOPY source destination [file [file]...] [options]

  • Source :

Source directory (server share path or drive: path).

  • Destination :

It is a desired dictionary (Drive: path or Server Share Path).

  • File:

To duplicate the specified file(s) (names/wildcards: the default is "*.*").

Copy options :

  • /S :

Subdirectories should be copied, but not empty ones.

  • /E :

Copy every subdirectory, even the empty ones.

  • /LEV:n :

Only the top n levels of the source directory tree should be copied.

  • /Z :

It is used to copy files in restartable mode.

  • /B:

It makes backup copies of your files.

  • /ZB :

It employs the restartable mode. When access is blocked, go to backup mode.

  • /EFSRAW :

Every encrypted file should be copied in EFS RAW mode.

  • /COPY:[copyflags] :

(/COPY: DAT is the default) What to COPY for files. (Copyflags: Data (D), Attributes (A), and Timestamps (T)).

O=Owner information, U=aUditing information, S=Security=NTFS ACLs.

  • /DCOPY: T :

COPY the timestamps in the directory.

  • /SEC :

Secure file copying is comparable to /COPY: DATS.

  • /COPYALL :

The equivalent of /COPY: DATSOU is to copy the entire file information.

  • /NOCOPY :

No file information is copied (helpful with /PURGE).

  • /SECFIX :

It improves file security for all files, even those that were skipped.

  • /TIMFIX :

All file timings should be fixed, even those for skipped files.

  • /PURGE :

If the destination files or directories are gone from the source, delete them.

  • /MIR :

/E plus /PURGE is the equivalent of mirroring a directory tree.

  • /MOV :

Files should be moved (deleted from the source after copying).

  • /MOVE :

Files and directories should be moved (deleted from the source after copying).

  • /A+:[RASHCNET] :

Files copied will now have the specified properties.

  • /A-:[RASHCNET] :

Take the specified properties out of duplicated files.

  • /CREATE :

Only create directory trees and files with zero length.

  • /FAT :

It generates the final files utilizing only 8.3 FAT file names.

  • /256 :

It disables the support for very long paths (more than 256 characters).

  • /MON:n :

Keep an eye on the source; rerun when more than n changes are noticed.

  • /MOT:m :

Keep an eye on the source; if anything changes, run it again in m minutes.

  • /RH:hhmm-hhmm :

Run hours - the window of time during which new copies may be initiated.

  • /PF :

For each file, rather than for each pass, check the run hours.

  • /IPG:n :

The inter-packet gap (ms), which releases bandwidth on slow lines.

  • /SL :

It replicate symbolic connections instead of the target.

  • /MT[:n] :

It makes n-thread multi-threaded copies (default 8). The value of n must be at least one and no more than 128. The /IPG and /EFSRAW options are incompatible with this one. For improved performance, use the /LOG option to redirect output.

File Selection options:

  • /A :

Just the files with the archive property set should be copied.

  • /M :

It is used to reset the property and copy just the files that have it set to "archive."

  • /IA:[RASHCNETO] :

It does not include any files unless at least one of the following characteristics is specified.

  • /XA:[RASHCNETO] :

A file will be excluded if any of the above properties are set.

  • /XF file [file]... :

It excludes files with the specified wildcards, paths, or names.

  • /XD dirs [dirs]... :

It disallows folders with the specified names or paths.

  • /XC :

Leave out updated files.

  • /XN :

Exclude more recent files.

  • /XO :

Leave out older files.

  • /XX :

It excludes supplementary folders and files.

  • /XL :

Delete lone files and folders.

  • /IS :

Add the same files.

  • /IT :

Modified files should be included using this command.

  • /MAX:n :

Files more than n bytes will be ignored as the maximum file size.

  • /MIN:n :

Files with a size of n bytes or less will be excluded.

  • /MAXAGE:n :

Files older than n days/date are excluded due to a maximum file age.

  • /MINAGE:n :

Files must be at least n days or more old to be included.

  • /MAXLAD:n :

Files with a maximum last access date of n are excluded.

  • /MINLAD:n :

Exclude files used after n days from the minimum last access date. (If n 1900, n is equal to the number of days; else, n is the date, in the format YYYYMMDD).

  • /XJ :

Junction points are not included. (Usually included by default).

  • /FFT :

Think of FAT file timings (2-second granularity).

  • /DST :

It is make up for DST time variations by one hour.

  • /XJD :

Directory junction points should be excluded.

  • /XJF :

File junction locations should be excluded.

Retry options :

  • /R:n :

Retry counts for unsuccessful copies are set to 1,000,000 by default.

  • /W:n :

There is a 30-second waiting period between trials by default.

  • /REG :

It saves the default values for /R:n and /W:n in the registry.

  • /TBD :

Hold off until share names are specified (retry error 67).

Logging options:

  • /L :

Don't copy, timestamp, or remove any files; just list them.

  • /X :

Report all additional files, not just the ones you chose.

  • /V :

It is used to create output that is verbose, and displays skipped files.

  • /TS :

Timestamps from the source file should be included in the result.

  • /FP :

It includes file names with their full paths in the output.

  • /BYTES :

Display sizes in bytes.

  • /NS :

Do not log file sizes if there is no size.

  • /NC :

Do not log file classes if there is no class.

  • /NFL :

Do not log file names or a file list.

  • /NDL :

Do not log directory names if no directory list is provided.

  • /NP :

Don't show the percentage copied if there is no progress.

  • /ETA :

It displays the copied files' predicted time of arrival.

  • /LOG: file :

The LOG file as the status output (overwrite existing log).

  • /LOG+:file :

The LOG file as the status output (append to existing log).

  • /UNILOG: file :

Create a UNICODE log file as the output status (overwrite existing log).

  • /UNILOG+:file :

Create a UNICODE log file as the output status (append to existing log).

  • /TEE :

Create a log file and output it to a console window.

  • /NJH :

Zero job header.

  • /NJS :

No job description.

  • /UNICODE :

Output is in UNICODE format.

Job options :

  • /JOB: jobname :

The named job file's parameters should be used.

  • /SAVE jobname :

Save the parameters to the specified job file.

  • /QUIT :

After processing the command line, exit (to view parameters).

  • /NOSD :

There is no source directory mentioned.

  • /NODD :

There is no designated destination directory.

  • /IF :

Add the files listed below.

Examples of robocopy :

robocopy c:\hope c:\hope2 *.txt

Any.txt file in this first example would be copied from the hope directory into the hope2 directory. Every time you want to copy a single file or many files rather than an entire directory, the file must be supplied after the destination directory.

robocopy c:\hope c:\hope2

In the aforementioned illustration, the robocopy command would copy every file (as opposed to directories) from the hope directory to the hope2 directory.

robocopy c:\hope c:\hope2 /e

The hope directory and the hope2 directory both get all of their files and folders-including empty ones-copied over.

robocopy c:\hope c:\hope2 /MIR

This example purges any files in the hope2 directory that don't exist in the hope directory while mirroring the contents of c:hope into c:hope2. Because the /mir switch deletes files that do not match those in the destination directory, use it with caution.

robocopy \\computer\hope C:\hope2

The next step in this example would be to copy any files located in the hope directory on the network computer known as the computer to the hope2 directory on the current computer.







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA