0

I need some help using for and xcopy to move files from one folder to another based on an input text file. What I need help with is matching files based on a pattern.

My input file looks like this:

12345  
abcd

My source file directory looks like this:

12345_hr.jpg  
12345_hr1.jpg  
abcd_hr.jpg  
abcd_hr1.jpg  

Lots of other files exist in this directory I want to ignore...

So I want to copy any file that matches the input file before the underscore (_); the end result would be all the files above being moved into a destination folder.

This is what I have used in the past when I want to do exact matches:

for /f "tokens=* delims=" %%a in ('type FileList.txt') do xcopy /hrkvy ".\SourceFolder\%%a" ".\DestinationFolder"

I just don't know how to make that work with a pattern match.

3
  • 1
    Possible duplicate of Wildcard file extensions xcopy
    – Worthwelle
    Aug 30, 2019 at 13:03
  • can you clarify a little more on what your desired outcome should be? is the input file essentially a list of folders, then if a file name (prior to the underscore) matches any one of those folder names, that file gets moved to that folder?
    – mael'
    Aug 30, 2019 at 13:21
  • The outcome is to move filenames prior to the underscore that match what's in the input file. I'm trying to pull out approx 15k files out of 100k+ that match the input file names.
    – Jason
    Aug 30, 2019 at 13:47

1 Answer 1

0

I got this figured out now. Here's what I was looking for:
for /f "tokens=* delims=" %%a in ('type list.txt') do xcopy /hrkvy "G:\Original\%%a"*.jpg "G:\Original\1"

1
  • 1. No need to type the list file, just read it by for /F immediately. 2. The quotation of the source should be "G:\Original\%%a_*.jpg", and there was the underscore missing...
    – aschipfl
    Sep 2, 2019 at 11:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .