Batch File to match file names to list

Posted on 2008-11-06
Last Modified: 2012-06-27
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.

Question by:robd2007
    LVL 38

    Accepted Solution

    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


    Author Comment

    Thank you for the accuracy and speed of your response. That works perfectly.

    You have made me a happy man :)

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
    VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now