Batch : Loop thru text file (with wild card) and move any matching files to parent folder.

Loop thru text file (with wild card) and move any matching files to parent folder.

1. I have one file called find.txt with data similar to the follow format.

ABC123
DEF123
HIJ123
KPI123
123456

2. I want a batch script to loop thru this text file and ALSO loop thru every file in current folder.

3. If match found (using wildcards - asterisk ) then move file to parent folder.

4. Example:
File ABC123xxxxx.pdf is a match to the first line of my find.txt file "*ABC123*  -  and should be moved to parent folder.

Similarly, file XXX_DEF123_XXX.pdf would also be a match to "DEF123" in find.txt.


WHat is the batch script ??

THanks all!
Patrick O'DeaAsked:
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.

Bill PrewCommented:
Give this a try, should do what you described...

@echo off
setlocal

set ListFile=find.txt

for /f "usebackq tokens=*" %%A in ("%ListFile%") do (
    if exist "*%%~A*.*" (
        move "*%%~A*.*" ..
    )
)

Open in new window


»bp
0

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
Patrick O'DeaAuthor Commented:
Perfect !

Thank you very much!!
0
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
Bat

From novice to tech pro — start learning today.