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

Patrick O'Dea
Patrick O'Dea used Ask the Experts™
on
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!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
IT / Software Engineering Consultant
Top Expert 2016
Commented:
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

Author

Commented:
Perfect !

Thank you very much!!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial