How to use Xcopy command in CMD (Command Prompt)

If you do not know, Xcopy is a command included in CMD, it is used to copy files or folders on Windows operating system. Later, in newer versions of Windows, Xcopy was replaced by Robocopy.

However, the Xcopy command has not been removed, which means you can still use this familiar Xcopy command because of its high compatibility.

#first. The Ultimate Guide to xcopy in CMD

If only copy [tệp] or [thư mục] Simply put, the command would be as simple as this:

xcopy [Đường-dẫn-file-hoặc-folder-cần-copy] [Đường-dẫn -đến-vị-trí-cần-paste]

For example, I use the command xcopy to copy files ghost32.exe from folder Setup go out Desktop then use the following command:

xcopy D:Setupghost32.exe C:UsersAdminDesktop

Read more the following article if you do not know the path to the file location: How to use CMD (Command Prompt) [đầy đủ & dễ hiểu]

tim-hieu-velenh-xcopy-in-cmd (3)

If the result is “1 (or more) File(s) copied”, then you have successfully copied the file or folder.

//*read more*//

Next problem………….

If you want to overwrite a file or folder (ie when you copy the same file name or folder name), the following message will appear:

tim-hieu-velenh-xcopy-in-cmd (1)

There are the following three options:

  • Yes (y): Accept to overwrite the old file.
  • No (n): Cancel copying, do not overwrite old files.
  • All(a): Overwrite all duplicate files.

=> You enter the corresponding symbols => then press Enter to execute the command.

Next up………….

You can copy [tệp] or [thư mục] to the path does not exist. Thus, xcopy will create a folder or file with the same name as the destination path.

See more:  How to turn off File Explorer's Folder Options on Windows 10

tim-hieu-velenh-xcopy-in-cmd (6)

For example, in this case Newfolder3 path does not exist. You can see xcopy asking if you want to create a file or directory?

  • If folder is selected [D], xcopy will create a directory with the correct name with the last path (Newfolder3).
  • And if you choose the file [F] then xcopy will copy the source file to the last existing path (Desktop), then rename it to be the same as the last pathname (Newfolder3).

//*end of further reading*//

#2. Things that you need to note about the xcopy command in CMD

  • You can cancel any order xcopy any by pressing the key combination Ctrl + C.
  • If you do not have permission to copy the file, an error message will appear Access Denied. Then you need to open CMD with Admin rights to be able to copy the file. If it still doesn’t work, add the parameter /r into the command to fix this.
  • When copying the file name must have an extension after it, otherwise it will not be able to copy. For example, I copy the file ghost32.exe but when using the command I just write ghost32 will be corrupted and cannot be copied.

tim-hieu-velenh-xcopy-in-cmd (2)

  • When using xcopy, by default all the properties of the newly copied file will be lost. Example File ghost32.exe My file has a read-only attribute, but after copying it in a new directory, this file will not have a read-only attribute.
  • Each time xcopy is used, only one file or directory can be copied per command.

#3. Advanced commands in xcopy

Note: All parameters like /v, /c, … all must be written later “Path-to-location-need-paste” dental.

First we can filter only copy files or folders with attributes. We can use the following two commands to perform in two cases as follows:

  • When you want the destination file or folder to have no attributes: xcopy /A
  • When you want the destination file or folder to keep its properties: xcopy /M

Next, we have the command to update the changed file using the following command:

xcopy /d:”month-day-year or day-month-year”

The effect of this command is to allow us to copy the source file only when it was last modified, after the date you entered above.

See more:  [SHARE] Windows 11 Virtual Desktop (VirtualBox and VMware)

For example, I have a file ghost32.exe in folder Setup last edited on 18/6/2021.

tim-hieu-velenh-xcopy-in-cmd (4)

And files ghost32.exe in folder Download last edited on 27/6/2021

tim-hieu-velenh-xcopy-in-cmd (5)

Currently I want to replace the file edited after the date 19/6/2021 then I will use the following command => and press Enter:

xcopy C:UsersAdminDownloadsProgramsghost32.exe D:Setupghost32.exe /d:06-19-2021

tim-hieu-velenh-xcopy-in-cmd (7)

Next we press y to agree to overwrite the old file.

tim-hieu-velenh-xcopy-in-cmd (9)

If I just write /d without writing extra time xcopy will only copy the file if the source file was last edited after the destination file.

You can refer to a few more parameters of xcopy below:

1. xcopy /w: Confirm before copying, press any button to start copying.

tim-hieu-velenh-xcopy-in-cmd (10)

2. xcopy /p: Confirm before copying, press y to agree, n to cancel.

tim-hieu-velenh-xcopy-in-cmd (11)

3. xcopy /c: Ignore copy errors, by default, the corrupted file will stop the copy process.

4. xcopy /v: Check the source file and the destination file after copying to make sure the two files are identical, avoiding corrupted or missing files after copying (Like checking MD5, SHA-1, …).

5. xcopy /q: Ignore xcopy’s source path when copying command line.

Prior to
tim-hieu-velenh-xcopy-in-cmd (12)
After

6. xcopy /f: Added command line to notify xcopy’s destination path when copying.

tim-hieu-velenh-xcopy-in-cmd (13)

7. xcopy /l: Remove the word “copied” after the copy result.

tim-hieu-velenh-xcopy-in-cmd (14)

Alternatively, you can try the following commands:

  1. xcopy /g: Create a decrypted destination file if the destination doesn’t support encryption.
  2. xcopy /u: Copy the source file only if it is already in the destination (The command is for overwriting only).
  3. xcopy /i: If the destination file does not exist, create a destination directory with the name of the target file and copy the source file to that directory. By default, when the destination file does not exist, xcopy will ask to create the source file as a file or a folder.
  4. xcopy /s: Copy more subfolders in the folder, ignoring empty folders. By default xcopy only copies files in the directory, ignoring the subdirectories in it.
  5. xcopy /e: Same as /s but will copy more empty subdirectories.
  6. xcopy /t: Copy only subfolders in a folder, ignoring all files, including files in subfolders.
  7. xcopy /k: Preserve the Read-only attribute of the target file.
  8. xcopy /r: Copy the file with the Read-only attribute. Usually used to fix Access Denied errors.
  9. xcopy /h: Copy the file with the Hidden or System attribute. By default xcopy will ignore files with the above attribute.
  10. xcopy /a: Preserve the Read-only, Hidden or System properties of the target file. Need to add the /h or /r parameter to be able to copy.
  11. xcopy /m: Remove the Read-only, Hidden, or System attribute of the target file. Need to add the /h or /r parameter to be able to copy.
  12. xcopy /y: Skip asking to overwrite files. Directly overwrite the file using this command.
  13. xcopy /z: File copying can be continued if the source or destination path connection is lost.
  14. xcopy /j: Copy files without caching. Recommended for large files. Can only be used from Windows Server 2008 R2 and later.
See more:  How to fix "No Boot Device Found" error when starting the computer

#4. Epilogue

That’s it, I’ve done almost all of the instructions for you xcopy commands in CMD okay then.

Hope you enjoy this article, don’t forget to visit the Knowledge Sharing Blog every day to learn more interesting knowledge 🙂

CTV: Hoang Tuan – techtipsnreview

Note: Was this article helpful to you? Don’t forget to rate the article, like and share it with your friends and family!


Source: How to use Xcopy command in CMD (Command Prompt)
– TechtipsnReview

Leave a Reply

Your email address will not be published. Required fields are marked *