Batch copy files from a list of partial names

时间:2016-07-11 23:17:53

标签: csv batch-file

I have a list of partial file names and I need to copy files out of a directory. I used the answer from this question to copy exact file names but now I need to do it for partial.

The file names look something like this

  • A123_154_DUT1_X123_Y345.csv

  • A123_176_DUT2_X124_Y346.csv

  • A123_196_DUT3_X125_Y347.csv

I have a list of the second half of the file names after DUT in a text file " File-List.txt"

  • DUT1_X123_Y345.csv

  • DUT2_X124_Y346.csv

  • DUT3_X125_Y347.csv

And this is what I have so far.

@echo off
set src_folder=C:\Test_Source
set dst_folder=C:\Test_Dest
set file_list=C:\File-List.txt
if not exist "%dst_folder%" mkdir "%dst_folder%"
for /f "tokens=*" %%i in (file-list.txt) DO (
  xcopy /S/E "%src_folder%\%%i" "%dst_folder%"
)

How do I amend this code to use the partial file names?

0 个答案:

没有答案