Windows file copy application

Windows Robocopy Command Tutorial with Examples To Copy Files In Safe Way

Robocopy or Robust File and Folder Copy application is very popular amongst Windows system administrators. Robocopy will copy the local or given file to the remote or destination location.

robocopy Features

The command robocopy provides very useful features for files copying over network. Below we will list some of them.

Resume Interrupted Copy when the network or remote host is down during a copy the copy operation can resume where it left.

Preserve File Attributes and timestamp of the copied file where owner and audit information is also preserved.

Ability To Update Copied File Attributes and Timestamps of the copied files and folders which will set to the latest date and time.

Administrator Owned File Copy is supported with the option /B .

Mirror Mode is provided to sync or mirror given files and folder or directory updated files will be updated and deleted files will be deleted on the target.

Skip Allready Existing Files by checking size and timestamp information and comparing it to the source and target.

Progress Bar will shown current copy operation graphically.

Multi-threaded copying which will allow copy, mirror multiple files and directories at the same time which will decrease the complete copy operation time.

robocopy Command Syntax

The general syntax of robocopy command is like below.

  • SOURCE is the source file or directory we want to copy
  • DESTINATION is the destination file or directory we want to copy
  • OPTIONS are different features or behaviors we want to use like recursive, verbose, extension filter, etc.

Copy Specified Folder

The most basic operation with robocopy is copying sources folders to the destination. In this example, we will copy the directory named mytest to the destination folder yourtest

After copy operation, some statistics are provided by robocopy

  • Start shows start time of copy operation
  • Source shows source directory
  • Dest shows destination directory
  • Files shows file filter
  • Options shows given options
  • Total shows total files and folders count
  • Copied shows copied files and folders count
  • Skipped shows not copied files and folders

Copy From Local System To Remote System

We can also copy a file and folders to the remote system. We will provide a remote system hostname or IP address before the destination path. We can use \\BACKUPSERVER or \\10.5.2.30 to specify the remote system.

In this example, we will copy the source directory named mytest to the remote system with IP address 192.168.122.46 under the path Users\ismail with the named yourtest .

Copy Only Given File Types or Extensions

robocopy provides some filtering features while copying files. We can specify the filenames and extensions we want to copy. This will skip other file names and extensions. We will provide the file name or extension after the destination folder.

In this example, we only want to copy *.txt extension files.

Читайте также:  Что такое pip линукс

We can see from the output that only one file is copied but there was more than one file. Copied file name and byte count is also printed.

Copy SubFolders

By default, only first level directories are copied to the destination. If we need to copy all level and subdirectories folders we should enable /S .

List Files

There is a very useful feature for robocopy where source files are not copied and just listed. This feature can be useful if we want to check existing files and folders. We can use /L option to print the list of files and directories.

As we can see from the output that all files and folders are skipped and not copied.

List Files Recursively

While robocopy is mainly used to copy files from remote to local or local to remove we can use /L and /S options in order to list remote files. We can merge two options list and recursive to list all level files and folders.

Copy Files Lower Than Given Size

While copying files we can specify the size of files we want to copy. In this example we will copy files those sizes are lower than 1K . We will use the /MAX option for this.

As we can see from the results some of the files are copied but some of them are not copied because of the size restriction.

Copy Files Higher Than Given Size

The reverse of the previous option is /MIN option . This will only copy files higher than the given size. In this example, we will copy files higher than 1K which is 1000 kilobytes.

Move Files

The default behavior of robocopy is copying files. Sometimes we may need to move files. This can be done with robocopy too. We will provide /MOV option in order to move files and folders.

Logging Operations

While doing copy and move operations we can also need some logs, especially in bulk data operations. We can write a log about specified operations with /LOG option. We can also specify the log file name y adding at the end of /LOG option. In this example, we will write robocopy operation log to log file named backup.log . This will prevent regular output

The log file can be listed with type command in MS-DOS command line like below.

Copy Given File Properties

Files and folders may have different properties. These properties can be used for different purposes like the listing owner, audit information, timestamps, etc. We can copy these attributes too with the robocopy command. Here are the attributes we can specify for the copy. We will also use /copy: option by adding the property we want to copy.

  • D is used to copy data properties
  • A used for attributes
  • T for time stamps
  • S is used for NTFS access control list simply ACL
  • O is used for the owner information
  • U is used for Auditing information

In this example, we will copy time stamp attributes or properties with the following command.

Copy All Attributes with /copyall

We can also copy files with all properties of attributes with the /copyall parameter like below. This is equal to the /copy:DATSOU .

Delete or Remove Destination Files and Directories That No Longer Exist In The Source

If we are trying to make an identical copy of the local files and directories to the remote we need to purge or remove remote files and directories that no longer exist in the source. We can use /purge option for this.

3 thoughts on “Windows Robocopy Command Tutorial with Examples To Copy Files In Safe Way”

Thanks for this article it was great but I already shifted to GS Richcopy 360. Using Robocopy was a mess, it gave errors one day or another. Now I am satisfied with GS Richcopy 360’s performance. I don’t think I am going back and use Robo. Thanks!

I’m doing fine with Robocopy, I won’t pay for any software to do something I can already do on my own. Thank you for your tutorial!

Thanks. Not a bad summary. I recommend two additions:
1) some examples for spotting new/changed files based on dates, along the /XC /XN /XO settings, especially in combos.
2) a note about how DANGEROUS the /MIR and /PURGE options can be, accidentally deleting files.

Читайте также:  Линукс с лучшей графикой

Windows copy command syntax and examples

Using copy command, we can copy files from one directory to another directory. This command is similar to the Linux cp command, but it does not match with the full functionality of cp. Windows copy command can be used to copy files only, we can’t copy directories.

The syntax and usecases of copy command are explained below with examples.

Copy the contents of a file to another file

Example: To copy a file from c:\data\file1.doc to D:\backup\file2.doc

If the destination file already exists you will be prompted for confirmation. To suppress this confirmation you can use /Y switch with copy command. This would be useful if you are executing copy command from a batch file.

If the destination file exists, the above command will overwrite the same without asking the user for confirmation.

Copy file to another directory

When we specify a directory path as the destination, the files will be copied with the same name. We can assign a different name by specifying the new name in the destination path. Example is shown below.

To copy the file 1.doc loated at c:\data\documents to the directory c:\data\newdocs

Copy files with white space in name

If the file name has white space within it, we can wrap up the name in double quotes.
Example: To copy file, my resume.doc to another folder

Copy multiple files

We can’t specify multiple file names in copy command. However, we can use wildcards to identify a group of files and then copy all of them in a single command.
For example, to copy all excel files from current folder to another folder F:\backup

To copy all files in current folder to another folder

Use of environment variables

We can use environment variables in the copy command to specify the path of the folders. Like USERPROFILE, SystemRoot, ProgramFiles, TEMP, WINDIR, APPDATA, HOMEPATH.

For example, to copy a file to a user’s documents folder

The above command copies the file to the My Documents folder of the current logged in user.

You may also want to read

Windows «copy» is funny. Type «copy 1 2» and the file «1» will be copied into a new file «2». Now separate them by a plus sign instead of a space (copy 1+2) and you’ll concatenate 1 and 2 and replace the old file «1» with the result of the concatenation!

Yes, we can concatenate two or more files using copy command. You need to separate the list of files using +. You can redirect the resultant data to a new file also.

The above command will not alter the file 1. It creates a new file 3 with the concatenated data of 1 & 2. If no file name is provided it stores the result in the first file.

My Win7 cannot find a copy command, and when i run xcopy, a window flashes and exits.

I have the same problem. If you solved it, could you please explain how?

If you can not find your copy.exe file, you can download it to your windows directory or C:\ Directory depending the setting on your OS you should also be able to copy and run it from system32 or system folder.

how can i combine 2 .exe files and be able to use both after concatenation

I want to copy 2 different files(.exe,.config) from source to destination server of windows.
can you please help me on this command.

Hello i have a problem with my cmd windows 7.when i try to copy a command. Like help > file.pdf. i mean in extension pdf because i have this problem only with .pdf extension but not with .txt.So whe i execute the command. No problem. Then when i go to open the file.pdf ftom user destination the file.pdf doesn’t open say that is corrupted.please do help me .thanks

i have a file contain many lines as sources and another file has the same numbre of lines as destinations. i want to copy first line as source( c:/test/*.txt) to first line in destination ( d:/test2/), secend line ( c:/test/*.pdf) to second line in destination ( E:/test3/)……

Can I use the DOS/Windows “COPY” command in a BAT file to copy a file or a short string of text to computer memory and then paste (Ctrl +V) that string or file into a document?

Читайте также:  Linux connect android usb

Windows Machine File Copy task

Azure Pipelines | Azure DevOps Server 2020 | Azure DevOps Server 2019 | TFS 2018 — TFS 2015

Use this task to copy application files and other artifacts such as PowerShell scripts and PowerShell-DSC modules that are required to install the application on Windows Machines. It uses RoboCopy, the command-line utility built for fast copying of data.

In Microsoft Team Foundation Server (TFS) 2018 and previous versions, build and release pipelines are called definitions, runs are called builds, service connections are called service endpoints, stages are called environments, and jobs are called phases.

YAML snippet

Arguments

Argument Description
Source The path to the files to copy. Can be a local physical path such as c:\files or a UNC path such as \\myserver\fileshare\files . You can use pre-defined system variables such as $(Build.Repository.LocalPath) (the working folder on the agent computer), which makes it easy to specify the location of the build artifacts on the computer that hosts the automation agent.
Machines A comma-separated list of machine FQDNs or IP addresses, optionally including the port number. Can be:
— The name of an Azure Resource Group.
— A comma-delimited list of machine names. Example: dbserver.fabrikam.com, dbserver_int.fabrikam.com:5986,192.168.34:5986
— An output variable from a previous task.
Admin Login The username of either a domain or a local administrative account on the target host(s).
— Formats such as domain\username, username, and machine-name\username are supported.
— UPN formats such as username@domain.com and built-in system accounts such as NT Authority\System are not supported.
Password The password for the administrative account specified above. Consider using a secret variable global to the build or release pipeline to hide the password. Example: $(passwordVariable)
Destination Folder The folder on the Windows machine(s) to which the files will be copied. Example: C:\FabrikamFibre\Web
Advanced — Clean Target Set this option to delete all the files in the destination folder before copying the new files to it.
Advanced — Copy Files in Parallel Set this option to copy files to all the target machines in parallel, which can speed up the copying process.
Advanced — Additional Arguments Arguments to pass to the RoboCopy process. Example: /min:33553332 /l
Select Machines By Depending on how you want to specify the machines in the group when using the Filter Criteria parameter, choose Machine Names or Tags.
Filter Criteria Optional. A list of machine names or tag names that identifies the machines that the task will target. The filter criteria can be:
— The name of an Azure Resource Group.
— An output variable from a previous task.
— A comma-delimited list of tag names or machine names.
Format when using machine names is a comma-separated list of the machine FQDNs or IP addresses.
Specify tag names for a filter as : Example: Role:DB;OS:Win8.1
Control options See Control options

Open source

This task is open source on GitHub. Feedback and contributions are welcome.

I get a system error 53 when using this task. Why?

Typically this occurs when the specified path cannot be located. This may be due to a firewall blocking the necessary ports for file and printer sharing, or an invalid path specification. For more details, see Error 53 on TechNet.

Do I need an agent?

You need at least one agent to run your build or release.

I’m having problems. How can I troubleshoot them?

I can’t select a default agent pool and I can’t queue my build or release. How do I fix this?

My NuGet push task is failing with the following error: «Error: unable to get local issuer certificate». How can I fix this?

This can be fixed by adding a trusted root certificate. You can either add the NODE_EXTRA_CA_CERTS=file environment variable to your build agent, or you can add the NODE.EXTRA.CA.CERTS=file task variable in your pipeline. See Environment variables for more details.

I use TFS on-premises and I don’t see some of these features. Why not?

Some of these features are available only on Azure Pipelines and not yet available on-premises. Some features are available on-premises if you have upgraded to the latest version of TFS.

Оцените статью