How To Copy Files and Backup With Xcopy In Windows

Windows provides very featureful command which is used to copy files can take backups named xcopy . Xcopy can be used copy files from one partition to other partition or a usb drive. Xcopy also supports incremental backup which create advantages while taking backups. We will look different usage examples of xcopy in this tutorial.

Help

Detailed help about xcopy command can be show with /? option like below.

1

$xcopy/?

Help

Copy Files

One of the most used type of xcopy is providing no option and just copying files from source path to the destination file. In this example we will provide source file named systeminfo.txt to the Downloads directory.

1

$xcopy systeminfo.txt Downloads

Copy Files

Ignore Errors

While copying files there may some errors related permission, corrupt data, changed data etc. These will create errors and these error will be printed to the terminal by default and these errors can be interrupt the copy operation. These errors can be ignored with /c option.

1

$xcopy/csysteminfo.txt Downloads

Backup Data Using Date and Time Stamp

One of the very useful feature is copying files according to their date and time stamp. While we are making backups regularly we can specify time which files those are changed specified time to backup. For example we take backup in following periodic dates.

01-04-2017

08-04-2017

15-04-2017

…

We can specify date where we will only copy files changed after that time. In this example only files those changed after 15-04-2017 will be copied.

Verbose Operation

Other useful feature is printing files during copy operation. This will give us feedback about the copy operation. We will use /f option for this.

1

$xcopy/fDownloads Downloads-backup

Verbose Operation

Copy Only Files Existing Destination

While copying files from source to the destination we can set a rule which will only copy the files existing in remote destination.

1

$xcopy/uDownloads Downloads-backup

Copy Hidden and System Files

Windows have different type of files attributed like System and Hidden . These files especially used by operating system or related applications. These files are not copied by default. In order to copy these type of files we will provide /h

1

$xcopy/hDownloads Downloads-backup

Exclude Files and Extension For Copy

While copying we may need to not copy some file names or extensions. For example a developer do not want to copy binary or temporary files. So we need to exclude these type of files and file names. We will create a file which stores file names and extensions line by line those will be excluded. We have a file ex.txt which have following contents.