Copy files with cmd command prompt in Windows 10

How to copy files with cmd using the Windows 10 command prompt?

To copy files with cmd to other Windows folders, use a script with copy in the command prompt. Two main options allow users to copy files in Windows batch scripts. The options are the copy and the xcopy commands. Of course, it is always possible to copy files and folders using the Windows system graphic user interface. But it’s more effective and recommended to script large and specific copies to avoid manipulation errors.

1. Copy files with Windows cmd

First, the MS-DOS scripting tool is way more efficient and effective than the drag and drop method to copy manually files and folders. Imagine you need to copy 250’000 files and need to make sure they were all copied without error. In this case, the dos copy command is the best option.

1.1 Copy a file and keep the same name and extension

First, to copy one file from a folder to another folder and keep the same name and the same extension. It is also possible to provide only the target folder, as the name will be kept by default. If you run two times the same script, the system displays this message to allow the overwriting of the files already in the target folder:

Overwrite C:\Folder2\file.txt? (Yes/No/All):

The All option will overwrite all the files during the copy of multiple files at the same time.

copy C:\Folder\file.txt C:\Folder2\file.txt

1.2 Copy a file and change the target name in cmd

In addition, you can change the name of the target file by simply specifying a different file name in the second argument. In this case the source file called file.txt is copied to another folder and is renamed as newfile.txt. To detect and copy multiple files with a specific pattern, use the wildcard symbol in the command. It allows to filter the source files by using the filename or the extension.

copy C:\Folder\file.txt C:\Folder2\newfile.txt

1.3 Copy multiple files with a filter on the name or extension

Here is how to copy all files with a specific pattern, i.e., with a specific extension or a specific name before the separator. To copy all specific files to another folder with the Windows command line, use the script below. The first option copies all the files with the txt extension and the second one copies only all the text files starting with the file prefix.

copy C:\Folder\*.txt C:\Folder2\

copy C:\Folder\file*.txt C:\Folder2\

2. Copy files and manage overwriting and integrity

Moreover, the dos copy command offers many other options, this list of options is not exhaustive. Like for example these useful options:

  • The copy /v to check that the new files are written without errors.
  • Or the copy /y to disable the prompt on overwriting.
  • Then the copy /-y to activate the overwriting warning prompt.

2.1 How to copy files and check their integrity?

To check the integrity of the new files after the copy, use the /v copy option. The MS DOS system will then check that the copied version has no corruption issue. It is useful with sensitive data or any file you must ensure has no errors while reading. For example, a professional PowerPoint presentation. The verify option only displays a message in case of an error occurred during the byte per byte verification. If not, no specific warning or information message is displayed in the prompt.

copy /v C:\Folder\file.txt C:\Folder2\file.txt
Copy files with cmd script and check the integrity in case of error - Windows 10
Copy files with cmd script and check the integrity in case of error

2.2 How to copy files without overwrite warnings?

In order not to display the prompt in case a file already exists, use the /y copy option. Then the system overwrites the target files with no explicit prompt. It means that in case of a very large copy of thousands of files, no warning will be displayed, and all the target files are overwritten.

Use this option carefully if manipulating different versions of the same file.

copy /y C:\Folder\file.txt C:\Folder2\file.txt
CMD script to copy  files in Windows 10 without overwrite warning
CMD script to copy files in Windows 10 without overwrite warning

2.3 How to enable a prompt before overwriting the target?

Finally, to enable the prompt explicitly during the file copy, use the same option but the opposite way. Indeed, the minus sign means disable the option: copy /-y. Use this option to avoid overwriting and potentially losing important files that has no backups. This allows to validate each file overwritten during the copy with the Yes option displayed in the prompt.

copy /-y C:\Folder\file.txt C:\Folder2\file.txt

3. Conclusion on how to copy files with cmd

As a conclusion, this short tutorial shows how to use cmd scripts to copy Windows files to a different folder. And also, how to use pattern to filter filename or extension and to manage file overwriting warnings. So, it is definitely worth learning to automate copies and to avoid errors.

Tutorials on how to manage files with MS-DOS or PowerShell