How To Copy Files Using Command Prompt in Windows ?

Different practical scripts examples to copy files using the Windows 10 command prompt.

To copy files using the command prompt to other Windows 10 folders, use the copy script from the MS-DOS Windows. 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.

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

Follow these 4 simple steps to copy files from the Windows Command Prompt
  1. Open the Windows Command Prompt by searching for cmd in the Windows Search box.
  2. Navigate to the source directory with the cd command, followed by the folder name.
  3. Use the copy command to duplicate files. For instance, to copy a file named ‘file.txt’ from ‘C:\Folder’ to ‘C:\Folder2’ and rename it as ‘newfile.txt,’ input: copy C:\Folder\file.txt C:\Folder2\newfile.txt
  4. Execute the previous command by pressing Enter.

1. Copy a file and keep same name and extension

First case, copy one file from one folder to another one and keep the same name and the same extension. It is also possible to provide only the target folder, then the file name will be kept by default. If you run two times the same script, the system displays this message to allow to overwrite 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

2. Copy Windows files and change the target name

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.

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

The copy command also allows users to list files recursively, to access folders and subfolders more effectively and have the full list of elements.

3. Copy multiple files using the command prompt and a filter

To detect and copy multiple files with a specific pattern, use the wildcard symbol in the command prompt. It allows to filter the source files by using the filename or the extension.

Here is how to copy all files with a specific pattern, i.e., a specific extension or a specific file name before the separator, which is the dot. 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\

4. Copy files and manage overwriting and integrity

Moreover, the MS-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.

5. Copy and check integrity of files using the command prompt

To copy Windows files using cmd and 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 of the file is not corrupted. It is useful with sensitive data or any other files, to ensure no errors occurred while reading and copying.

For example, a professional PowerPoint presentation. that you spent hours and hours to craft. 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
How to copy files using the Windows command prompt?
How to copy files using the command prompt in Windows?

6. Copy files without displaying overwrite warnings

In order not to display the prompt in case the target file already exists, use the copy /y option. Then the system overwrites the target files with no explicit prompt or message.

WARNING: 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
How to copy Windows 10 files using MS-DOS? Example with overwrite warnings.
Copy Windows files using command prompt without overwrite warnings

7. Enable a prompt before overwriting target files

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

About file copy using the Windows command prompt

As a conclusion, this cmd tutorial explains how to copy files from a location to another, using the command prompt on Windows 10 or Windows 11. And also, how to use patterns to filter filenames or extensions and to manage file overwriting warnings. So, it is definitely worth learning to automate large copies and to avoid errors.

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