Batch File to match file names to list

Hi. I need to match a list of file names to a search of a specific directory and output a list of unmatched files. It has been suggested to me that this would be easy with a batch file.

What I have is a text file that has a list of filenames, File1.*, File2.* etc and i need a search of a directory,(and all subdirectories) to see if these exist, and if not, save the list of missing filename to a seperate file.

Would a batch file be the best solution? and if so, how would i go about this.

Who is Participating?

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

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.

Paste the script below into a text file with a .cmd extension.  Customize the value of the list variable with the location of the file list.  Customize the value of the folder variable with the location of the folder to search under.  Running the script will write output to the text file specified in the log variable.

@echo off
set list=list.txt
set folder=c:\files
set log=notfound.txt
if exist "%log%" del "%log%"
for /F "tokens=*" %%G in ('type "%list%"') do (
 dir "%folder%\%%G" /A:-D /B /S > NUL 2>&1
 if errorlevel 1 echo %%G>>"%log%"

Open in new window


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
robd2007Author Commented:
Thank you for the accuracy and speed of your response. That works perfectly.

You have made me a happy man :)
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
Microsoft DOS

From novice to tech pro — start learning today.