Suppose for some reason your Windows computer is not running or Infected with the virus. There are some important files in c drive and you need to copy them using the command line. In this post, we will discuss a nice function of windows which is XCopy.
The XCopy is a Command Prompt command used to copy one or more files or folders from one location to another location. The XCopy command, with its many options and ability to copy entire directories, is similar to, but much more powerful than, the copy command. The Robocopy command is also similar to the xCopy but has even more options.
The XCopy is an excellent solution for syncing one folder to another. The XCopy command is available from within the Command Prompt in all Windows operating systems including Windows 10. The advantages of XCOPY has been listed below:
- XCOPY can copy directories.
- XCOPY can exclude files based on file names or extensions.
- XCOPY will automatically delete the read-only attribute when copying files from the CDROM to the hard drive.
- XCOPY can recursively copy all files including subdirectories and can copy the source directory structure as it is.
- XCOPY can help identify updated files (based on archive attributes or based on the given expiration date), thus it is great for incremental backup needs.
Basic Example of XCopy
Use the following syntax for the XCopy command:
xcopy C:\Files E:\Files /i
xcopy C:\Videos "\\SERVER\Media Backup" /f /j /s /w /z
XCopy Command Syntax
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]…] [/?]
Xcopy Command Options
|source||This defines the files or top-level folder that you want to copy from. The source is the only required parameter in the xcopy command. Use quotes around the source if it contains spaces.|
|destination||This option specifies the location where the source files or folders should be copied to. If no destination is listed, the files or folders will be copied to the same folder you run the xcopy command from. Use quotes around the destination if it contains spaces.|
|/a||Using this option will only copy archive files found in the source. You can not use /a and /m together.|
|/b||Use this option to copy the symbolic link itself instead of the link target. 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 xcopy command with /d option and a specific date, in MM-DD-YYYY format, to copy files changed on or after that date. You can also use this option without specifying a specific date to copy only those files in a source that are newer than the same files that already exist in the destination. This is helpful when using the xcopy command to perform regular file backups.|
|/e||When used alone or with /s, this option is the same as /s but will also create empty folders in a destination that were also empty in the source. The /e option can also be used together with the /t option to include empty directories and subdirectories found in the source in the directory structure created in the destination.|
|/f||This option will display the full path and file name of both the source and destination files being copied.|
|/g||Using the xcopy command with this option allows you to copy encrypted files in 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||The xcopy command does not copy hidden files or system files by default but will when using this option.|
|/i||Use the /i option to force xcopy to assume that destination is a directory. If you don’t use this option, and you’re copying from source that is a directory or group of files and copying to the destination that doesn’t exist, the xcopy command will prompt you to enter whether a destination is a file or directory.|
|/j||This option copies files without buffering, a feature useful for very big files. This xcopy command option was first available in Windows 7.|
|/k||Use this option when copying read-only files to retain that file attribute in the destination.|
|/l||Use this option to show a list of the files and folders to be copied… but no copying is done. The /l option is useful if you’re building a complicated xcopy command with several options and you’d like to see how it would function hypothetically.|
|/m||This option is identical to the /a option but the xcopy command will turn off the archive attribute after copying the file. You can not use /m and /a together.|
|/n||This option creates files and folders in the destination using short file names. This option is only useful when you’re using the xcopy command to copy files to a destination that exists on a drive formatted to an older file system like FAT that does not support long file names.|
|/o||Retains ownership and Access Control List (ACL) information in the files written in the destination.|
|/p||When using this option, you’ll be prompted before the creation of each file in the destination.|
|/q||A kind of the opposite of the /f option, the /q switch will put xcopy into “quiet” mode, skipping the on-screen display of each file being copied.|
|/r||Use this option to overwrite read-only files in the destination. If you don’t use this option when you want to overwrite a read-only file in destination, you’ll be prompted with an “Access denied” message and the xcopy command will stop running.|
|/s||Use this option to copy directories, subdirectories, and the files contained within them, in addition to the files in the root of the source. Empty folders will not be recreated.|
|/t||This option forces the xcopy command to create a directory structure in the destination but not to copy any of the files. In other words, the folders and subfolders found in the source will be created but there we are no files. Empty folders will not be created.|
|/u||This option will only copy files in the source that are already in the destination.|
|/v||This option verifies each file as it’s written, based on its size, to make sure they’re identical. Verification was built into the xcopy command beginning in Windows XP, so this option does nothing in later versions of Windows and is only included for compatibility with older MS-DOS files.|
|/w||Use the /w option to present a “Press any key when ready to being copying file(s)” message. The xcopy command will begin copying files as instructed after you confirm with a keypress. This option is not the same as the /p option which asks for verification before each file copy.|
|/x||This option copies file audit settings and System Access Control List (SACL) information. You imply /o when you use the /x option.|
|/y||Use this option to stop the xcopy command from prompting you about overwriting files from sources that already exist in the destination.|
|/-y||Use this option to force the xcopy command to prompt you about overwriting files. This might seem like a strange option to existing since this is the default behavior of xcopy but the /y option may be preset in the COPYCMD environment variable on some computers, making this option necessary.|
|/z||This option allows the xcopy command to safely stop copying files when a network connection is lost and then resume copying from where it left off once the connection is reestablished. This option also shows the percentage copied for each file during the copy process.|
|/exclude:file1[+file2][+file3]…||This option allows you to specify one or more file names containing a list of search strings you want the xcopy command to use to determine files and/or folders to skip when copying.|
|/?||Use the help switch with the xcopy command to show detailed help about the command. Executing xcopy /? is the same as using the help command to execute help xcopy.|