Copy recursively files and folders in cmd with xcopy

To copy a single file or multiple files recursively with the Windows command prompt, use the xcopy command. The xcopy command is very similar to the copy command but it handles recursion and has many other options mainly related to recursion.

How to recursively copy files and folders with windows cmd?


Indeed, when copying a large number of files and folders, it is useful to be able to copy all the files without naming them explicitly.

Perhaps the most important and useful option of the xcopy command is the recursive option.

The “s” option indicates to copy all directories and subdirectories with their contents. An exception for empty directories. Indeed with this option, by default the system does not copy empty directories.

xcopy /s xcopy /s SubFolder* SubFolder_2

To avoid the prompt to overwrite existing files

Use this command with the “y” option:

xcopy /s /y SubFolder* SubFolder_2

Other useful xcopy options to better control file copying

The “c” option is used to ignore errors during copying. Useful when copying a large number of files. Thus, at the end of the copy, only the errors are to be corrected and not all the files.

xcopy /s /c Sous-dossier* Sous-dossier_2

xcopy’s “f” option displays full source and target filenames with paths. The paths are absolute, that is, they start from the Windows drive letter.

xcopy /s /f SubFolder* SubFolder_2

The xcopy /l command is a simulation of the copy.

Use the “l” option to display only a complete list of files to copy. But don’t actually copy the files.

xcopy /s /l SubFolder* SubFolder_2

Tells the system not to display messages from xcopy on the prompt screen. Can be useful in batch scripts for example. The result is that the terminal only displays the total number of files copied.

xcopy /s /q SubFolder* SubFolder_2

To copy only existing files on both source and destination, use the xcopy /u option. This is a useful option to update a target folder for example. And align all latest versions in the target with a given source folder.

xcopy /s /u SubFolder* SubFolder_2

The verification option is xcopy /v. Verifies each file after copying, verifying that the source and target are identical. Useful for sensitive data or large files.

xcopy /s /v SubFolder* SubFolder_2

Displays this message in the Windows prompt to manually start copying files: “Press any key to begin copying file(s)”. This option adds a manual control step to the copy process. Interesting in an integrated batch with other control steps.

xcopy /s /w SubFolder* SubFolder_2

In this article on xcopy , we saw some options available in this powerful recursive command.