Xcopy command in Windows
The robocopy command is similar, but with more options.
Availability of the Xcopy . command
This command is available from within Command Prompt in all Windows operating systems including Windows 10, Windows 8, Windows 7, Windows Vista, Windows XP, Windows 98, etc. See How to open Command Prompt if you need help.
You can also access commands in MS-DOS as DOS commands.
Xcopy command syntax
Use the following syntax for the xcopy command:
xcopy source [destination] [/a] [/b] [/c] [/d [:date]] [/e] [/f] [/g] [/h] [/i] [/j] [/k] [/l] [/m] [/n] [/o] [/p] [/q] [/r] [/s] [/t] [/u] [/v] [/w] [/x] [/y] [/-y] [/z] [/exclude:file1[+file2][+file3].] [/?]
Note : The availability of some xcopy command switches and command syntax may vary between operating systems.
Xcopy command options
Option | Describe |
source | This option identifies the top-level files or folders that you want to copy. Source is the only required parameter. Use quotes around source if it contains spaces. |
destination | This option specifies the location where the folder or source file will be copied to. If no destination is listed, the files or folders will be copied to the same folder where you ran the xcopy command. Use double quotes around destination if it contains spaces. |
/a | Using this option will only copy archives found in source. You cannot use /a and /m together. |
/b | Use this option to copy the symbolic link itself instead of the link destination. This option was first available in Windows Vista. |
/c | This option forces xcopy to continue even if it encounters an error. |
/d [ : date ] | Use the command with the /d option and a specific date, in the format MM-DD-YYYY , to copy files that have changed on or after that date. You can also use this option without specifying a specific date to copy only files in the source that are newer than the same file that already exists in destination. This is useful when using xcopy to perform regular file backups. |
/e | When used alone or with /s , this option is the same as /s but will also create empty directories in destination that are also empty in source. The /e option can also be used in conjunction with the /t option to include empty directories and subdirectories found in source in the directory structure created in destination. |
/f | This option will display the full path and name of both the source and destination files being copied. |
/g | Using xcopy with this option allows you to copy files encrypted in the source to a destination that does not support encryption. This option will not work when copying files from an EFS-encrypted drive to a non-EFS-encrypted drive. |
/H | Use this option to copy hidden files or system files. |
/i | Use the /i option to force xcopy to assume that destination is a directory. If you do not use this option and you are copying from source as a folder or group of files and copying to a destination that does not exist, the xcopy command prompts you to enter destination as a file or directory. |
/j | This option copies files without saving buffers, a useful feature for very large files. This option was first available in Windows 7. |
/k | Use this option when copying read-only files to retain the file attribute in destination . |
/l | Use this option to display a list of files and folders to be copied. but no copying is actually performed. The /l option is useful if you are building a complex command with a lot of options and you want to see how it will hypothetically work. |
/m | This option is the same as the /a option, but xcopy disables the archive attribute after copying the file. You cannot use /m and /a together. |
/n | This option creates files and folders in destination using short filenames. This option is only useful when you are using a command to copy files to a destination that exists on a drive that has been formatted to an old file system such as FAT that does not support long filenames. |
/o | Retain ownership and Access Control List (ACL) information in the file recorded in destination . |
/p | When using this option, you will be prompted before creating each wait in destination . |
/q | In contrast to the /f option , the /q switch will put xcopy in Quiet mode, ignoring the display on the screen for each copied file. |
/r | Use this option to overwrite read-only files in destination . If you don't use this option when you want to overwrite a read-only file in destination , you will get an "Access denied" message and the command will stop running. |
/S | Use this option to copy directories, subdirectories and the files contained within them, in addition to those in the source 's root directory . Empty folders will not be recreated. |
/t | This option forces the xcopy command to create a directory structure in destination but does not copy any files. In other words, directories and subdirectories found in source will be created but the user has no files. Empty folders will not be created. |
/u | This option will only copy files in source that are already in destination . |
/v | This option verifies each file as it is written, based on size, to ensure they are identical. Verification is built into the start command on Windows XP, so this option has no effect in new versions of Windows and is only included for compatibility with older MS-DOS files. |
/w | Use the /w option to bring up the message "Press any key when ready to be copying file(s)". The command will start copying files according to the instructions after you confirm with a keystroke. This option, unlike the /p option, requires pre-verification of each file copy. |
/x | This option copies file inspection settings and System Access Control List (SACL) information. Do you mean the same as the /o option when using the /x option . |
/y | Use this option to prevent the command from prompting you to overwrite files from source that already exist in destination . |
/-y | Use this option to force the command to prompt you about overwriting the file. This seems like an odd option that exists since this is xcopy's default behavior, but the /y option can be preset in the COPYCMD environment variable on some computers, making this option so necessary. |
/z | This option allows the xcopy command to safely stop copying files when the network connection is lost and then resume copying from the stopped location after the connection is re-established. This option also shows the percentage copied for each file during the copying process. |
/exclude: file1 [ + file2 ][ + file3 ]. | This option allows you to specify one or more filenames containing a list of search strings that you want the command to use to identify files and/or directories to ignore when copying. |
/? | Use switch help with xcopy to display detailed help about the command. Execute command xcopy /? same as using the help command to execute help xcopy . |
Note : The xcopy command will add an archive attribute to files in destination , regardless of whether that attribute is enabled or disabled on files in source.
Xcopy command example
Here are some examples of how to use this command:
Copy files to new folder
xcopy C:Files E:Files /i
In the above example, the files contained in the source folder source of C: Files are copied to the destination, a new folder [/ i] on drive E is called Files.
No subdirectories, nor any files contained within them, will be copied because the /s option is not used.
Xcopy backup script
xcopy "C:Important Files" D:Backup /c /d /e /h /i /k /q /r /s /x /y
In this example, xcopy is designed to act as a backup solution. Try this if you want to use xcopy instead of a software program to back up your files. Put the command as shown above in a script and schedule it to run nightly.
As shown above, the command is used to copy all files and directories [/s] newer than those already copied [/d] , including empty directories [/e ] and the hidden file [/h] , from the source C:Important Files to the destination D:Backup , which is the directory [/i] .
For example, there are some read-only files that want to update in destination [/r] and want to keep that attribute after being copied [/k] . The example also wants to ensure that any ownership and auditing settings in the files being copied [/x] are maintained. Finally, since the example is running xcopy in a script, it doesn't need to see any information about the files as they are copied [/q] , the example doesn't want to be prompted to overwrite each file [/y] and also don't want the command to stop if it gets an error [/c].
Copy files and folders over the network
xcopy C:Videos "SERVERMedia Backup" /f /j /s /w /z
Here, the command is used to copy all the files, subdirectories and files contained in the subdirectory [/s] from the source C:Videos to the Media Backup destination folder located on a network computer named as SERVER. Some really large video files are being copied, so write buffering should be turned off to improve copying [/j] and since the copying is happening over the network, the author wanted to be able to continue continue copying if network connection is lost [/z] midway.
The example would also like to be prompted to start the process before actually doing anything [/w] and see all the details about what files are being copied [/f].
Duplicate directory structure cấu
xcopy C:Client032 C:Client033 /t /e
In this last example, the article has a complete source of well-organized files and folders in C:Client032 for a client. The article created an empty target directory, Client033 , for a new client but didn't want any files copied - merely an empty directory structure [/t] to organize and prepare. There are some empty directories in C:Client032 that are applicable to the new client, so the example wants to make sure that they are copied as well [/e].
You should read it
- How to use Xcopy command in Command Prompt
- Del command in Windows
- Set command in Windows
- Cmd command in Windows
- Command at in Windows
- The chkntfs command in Windows
- Fc command in Windows
- The echo command in Windows
- Reg command copy in Windows
- The command reg add in Windows
- Rem command in Windows
- Doskey command in Windows
Maybe you are interested
Chromebooks get a new factory reset option that doesn't wipe everything
How to Use Windows Advanced Boot Options to Troubleshoot Faster
10 Ways to Fix Missing Bluetooth Option in Windows 11
7 Windows Recovery Options to Make System Recovery Easy
How to Remove 'Edit with Paint' Option in Windows 11
Microsoft tests a new Power Mode option to help Windows 11 save more energy