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.

robd2007Asked:
Who is Participating?
 
Shift-3Connect With a Mentor Commented:
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
setlocal
 
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

0
 
robd2007Author Commented:
Thank you for the accuracy and speed of your response. That works perfectly.

You have made me a happy man :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.