0

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?

Community
  • 1
  • 1
  • Welcome to Stack Overflow! Can you elaborate on how your code doesn't work? What were you expecting, and what actually happened? If you got an exception/error, post the line it occurred on and the exception/error details. Please [edit] these details into your post so that other users are able to help you. See also [ask], and be sure you have provided a [mcve]. – Scott Weldon Jul 11 '16 at 23:31
  • 1
    If only 1 file will match just use a [wildcard](http://ss64.com/nt/syntax-wildcards.html) `*`: `xcopy /S/E "%src_folder%\*%%i" "%dst_folder%"` – DavidPostill Jul 11 '16 at 23:32
  • `copy "c:\folder\*_DUT1_X123_Y*.csv c:\somewhere\*.*`. If your code doesn't work DON'T POST OBFUSCATED CODE. ALSO DON"T POST CODE until you have removed `ECHO OFF` which means hide my faulty command line from me. –  Jul 11 '16 at 23:33
  • Thank you. I didn't know that using a wildcard would be sufficient, I'd seen whole search functions for other languages. Because I want to load the partial names from the "File-List.txt" I still need to run the tokens line but I didn't know I could just put a wildcard in the xcopy expression. Amending the above code to this works perfectly. for /f "tokens=*" %%i in (file-list.txt) DO ( xcopy /S/E "%src_folder%\%%i" "%dst_folder%" – Maxwell Roth Jul 12 '16 at 13:47

0 Answers0