Create a Batch File That Produces a Specific List

This I think should be very simple but I can't seem to figure it out.  What I am trying to accomplish is to create a batch file that looks in a specific Parent folder and all files that equal *fanart.jpg should be copied into a separate folder and overwriting any file that already has that name.
jjmekkattilAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ThomasMcA2Commented:
You only need a single line to do that:
copy /y c:\parent\path\*fanart.jpg d:\destination\path\

Open in new window

Note that c: and d: are drive letters. Change them (and the paths) to match your requirements.
jjmekkattilAuthor Commented:
Well the above line is good if I'm looking for a particular file (*fanart.jpg) within a particular folder within the parent folder.  What I am looking for is all the *fanart.jpg that resides in the parent and to have those copied into a different location.
NVITEnd-user supportCommented:
To find only in parent...
xcopy /y /h c:\parent\*fanart.jpg c:\target\

To find in parent and all subfolders...
xcopy /s /y /h c:\parent\*fanart.jpg c:\target\

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

jjmekkattilAuthor Commented:
That did it!
jjmekkattilAuthor Commented:
Actually take that back how do I get it extracted from the folders when being copied over?
NVITEnd-user supportCommented:
...extracted from the folders
If you mean copy them to a single folder, then...
Note: Since all files are placed in one folder, any duplicate names are overwritten w/o warning.

set filepattern=*fanart.*
set parent=c:\parent
set target=c:\target
for /f %%a in ('dir /b /s "%parent%\%filepattern%"') do (
 copy /y "%%a" "%target%\"
)

Open in new window

NVITEnd-user supportCommented:
What I am looking for is all the *fanart.jpg that resides in the parent and to have those copied into a different location.
jjmekkattil, that's what ThomasMcA2's solution does.

But, I think you meant something else since you accepted my solution.

Or, did you?
jjmekkattilAuthor Commented:
Well again it sort of worked, the solution I accepted, but I didn't realize that the folders would come along as well.  Let me step back within the parent folder there is about 365 individual folder and in each of those folders has a *fanart.jpg.  I wanted to run a batch that would look at the subfolders extract the *fanart.jpg and place them, as those files and not the folders that the jpgs reside in, in a different location.
NVITEnd-user supportCommented:
My second solution should do it.
jjmekkattilAuthor Commented:
No that didn't do it...it was trying to copy everything.
NVITEnd-user supportCommented:
No that didn't do it...it was trying to copy everything.
It should be copying only *fanart.jpg files. Isn't that what you want?

...within the parent folder there is about 365 individual folder and in each of those folders has a *fanart.jpg....look at the subfolders extract the *fanart.jpg and place them, as those files and not the folders that the jpgs reside in...
Are these *fanart.jpg files uniquely named? If not, they will be overwritten at the destination.

If they are not uniquely named, they would need to be, before copying them to the same folder.

...in a different location.
Do you want each file in the same folder? If so, see above comment.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.