Windows batch file to copy files from one directory to another using a list of files in a text file

Possible answer:

Here is an example Windows batch file that reads a list of file names from a text file and copies them from a source directory to a destination directory:

@echo off
set SRC_DIR=C:\Source
set DST_DIR=D:\Destination
set LIST_FILE=list.txt
for /F %%F in (%LIST_FILE%) do (
  copy /Y "%SRC_DIR%\%%F" "%DST_DIR%\"
)

Explanation:

  • The @echo off command disables the display of commands in the console.
  • The set commands define the source and destination directories, and the name of the file that contains the list of file names to copy. You can modify these values as needed.
  • The for /F command reads a file line by line and assigns each line to the variable %%F. The %LIST_FILE% parameter specifies the path to the file that contains the list of file names. The /F option tells for to interpret the file as text and skip blank lines, comments, and delimiters (by default, spaces and tabs).
  • The copy command copies a file from the source directory to the destination directory. The /Y option suppresses the confirmation prompt if a file already exists in the destination directory with the same name as the one being copied. The %SRC_DIR%\%%F and %DST_DIR%\ parameters specify the paths to the source and destination files, respectively. The %%F variable contains the name of the file to copy, extracted from the list file.

Note: Make sure the list file contains only the file names (or paths relative to the source directory) and each name is on a separate line.

Related articles:

Effortlessly Transfer Multiple Files: A Guide to Creating a Windows Batch File
A Windows Batch File is a powerful tool that automates repetitive tasks on your computer. One task that can be automated with a batch file is the transfer of multiple files. If you're tired of manually transferring files, then this guide is for you.

Streamline your File Management with Windows Batch Files
If you're someone who frequently works with computer files, then you know how time-consuming it can be to perform repetitive tasks such as managing folders, renaming files, or copying data from one location to another. However, you can simplify these tasks by using Windows batch files.

Copy Files in Batches: Creating a Windows Batch File using a List of Files
Copying files in batches can be a time-efficient and easy way to transfer large amounts of data from one location to another. The process of copying files can become repetitive and burdensome when dealing with a large number of files that need to be copied. In such cases, creating a Windows batch file can help automate the process and save time.