Windows Copy Operation With Xcopy Command Tutorial With Examples – POFTUT

Windows Copy Operation With Xcopy Command Tutorial With Examples


Windows have different tools and commands to copy file, folders and subfolders. Xcopy is one of the most popular copying command. Xcopy comes builtin with all Windows operating systems. In this tutorial we will look different usage types and examples of Windows xcopy command.

Help

Help about xcopy command can be get with the following.

$ xcopy /?
Help
Help

Copy File

Basic usage of the xcopy command is copying gives file. We will just specify the source file and destination file name and path. We can also specify in relative paths like below.

$ xcopy poet.txt newpoet.txt
Copy File
Copy File

While copying we specify the source as sfile with F . After copy operation is completed information about the operation is printed like file count source file name etc.

Copy Folder

Copy folder is an other useful feature of the xcopy command. We will copy cygwin64 source folder as new_cygwin64 in the example below.

$ xcopy cygwin64 new_cygwin64
Copy Folder
Copy Folder

Copy Recursively All Folder and SubFolders

In previous example we have given the source folder. The only file contents of the source folder is copied in to the destination folder. We can use /S option to copy all folders, sub folders and related files recursively like below.

$ xcopy /S cygwin64 new_cygwin64
Copy Recursively All Folder and SubFolders
Copy Recursively All Folder and SubFolders

As we can see from screenshot all sub folders and files are copied.

Prompt Before Starting Copy

Another useful feature is prompting before starting copying. This will prevent accidental copying or unwanted overwriting of destination files and folders. We will use /W option for this feature.

$  xcopy /W poet.txt newpoet.txt

Prompt Before Each File Creation

Another alternative for user acceptation by prompting is prompting in each file creation. This may be a useful feature for some file and folder copy but in bulk operation this is not so useful. We will use /P option to prompt for each file copy operations like below.

$ xcopy /P poet.txt newpoet.txt
Prompt Before Each File Creation
Prompt Before Each File Creation

Copy Files With Archive Attributes

While copying files by default some files attributes are not copied. Archive attributes are some of them. We can enable copying archive attributes with /A option like below.

$ xcopy /A poet.txt newpoet.txt

Copy Hidden and System Files

Hidden and System files are important part of the operating systems. They are use by Windows operating system internally. If we are making copy on these type of files they are not copied by default. We cna enable copying them with /H .

$ xcopy /H poet.txt newpoet.txt

Copy Files Those Changed After Specific Date

For copy operations those are done same period there are some useful features which will make copy more efficient. We can specify some date and time where these will be used to which files will be copied after that time. In this example we will only copy files those are changed after 01-01-2017

$ xcopy /D:01-01-2017 poet.txt newpoet.txt

LEARN MORE  Linux ulimit Command Tutorial

Leave a Comment