- 1 year ago
cmd - Find and copy specific files (from a list) along with their full path
To find and copy specific files from a list, along with their full paths, you can use a batch script in Windows Command Prompt (cmd). Here's an example of how you can accomplish this:
Create a text file (
filelist.txt
, for example) that contains the list of files you want to find and copy. Each file should be listed on a separate line.Example
filelist.txt
contents:vbnetC:\path\to\file1.txt
C:\path\to\file2.txt
C:\path\to\file3.txt
Open a Command Prompt session and navigate to the directory where you want to copy the files.
Run the following batch script to read the
filelist.txt
and copy the files along with their full paths:batch@echo off
set "destination=C:\path\to\destination\folder"
set "filelist=filelist.txt"
for /f "usebackq delims=" %%F in ("%filelist%") do (
echo Copying "%%F" to "%destination%\%%~nxF"
xcopy /y /i "%%F" "%destination%\%%~nxF"
)
- Replace
"C:\path\to\destination\folder"
with the actual path of the destination folder where you want to copy the files. - Replace
"filelist.txt"
with the actual name of your file list if it differs.
- Replace
Save the batch script with a
.bat
extension (e.g.,copy_files.bat
) in the same directory as thefilelist.txt
file.Double-click the batch script to execute it. The script will iterate through each line in the
filelist.txt
, copy the corresponding file to the specified destination folder, and display the copied file's full path.
The batch script uses a for /f
loop to read each line of the filelist.txt
file and copies the listed files using xcopy
. The /y
flag ensures that existing files are overwritten, and the /i
flag treats the destination as a directory if copying multiple files.
Make sure you have appropriate read permissions to access the files listed in filelist.txt
, and ensure that the destination folder exists before running the script.