Windows batch, recursively copy files

  • 11 months ago

1 / 1

You can use a Windows batch script to recursively copy files from one directory to another. Here's an example of how you can achieve this:

@echo off

set "sourceDir=C:\path\to\source\directory"
set "destinationDir=C:\path\to\destination\directory"

echo Copying files from %sourceDir% to %destinationDir%
xcopy "%sourceDir%\*" "%destinationDir%\" /E /I /Y

echo Files copied successfully!

Replace C:\path\to\source\directory with the path of the source directory you want to copy from, and replace C:\path\to\destination\directory with the path of the destination directory where you want to copy the files to.

In this example, the xcopy command is used with the following options:

  • /E: Copies directories and subdirectories, including empty ones.
  • /I: If the destination does not exist and you're copying multiple files, assumes that the destination must be a directory.
  • /Y: Suppresses the prompting to confirm overwriting of destination files.

After copying the files, the script displays a success message and waits for the user to press any key.

Save the script as a .bat file and run it in a Command Prompt window. Make sure to test it on a smaller dataset before using it on a large number of files.