Batch script to copy multiple files (based on string in filename) from all folders under a directory to another folder

batch-file

Hi I am looking for a (simple) batch script for Windows XP to copy pdf files with different filenames but having the same reference numbers in their filenames to a specific folder in a different drive.

E.g.

Copy all pdf's with reference number 111 to folder "test"

Source files in F drive

F:\folder 1\filename 1_111.pdf
F:\folder 1\folder 2\filename 2_111.pdf

Destination folder in C drive

C:\test\

I am a novice, so thank you in advance for your help.

Regards,
Olive

Best Answer

This is another option:

@echo off
for /f "delims=" %%a in ('xcopy /l /e /y "F:\folder 1\*111*.pdf" "c:\test\" ^|find ":"') do copy "%%a" "c:\test"
Related Topic