Searching a folder for specific files

Posted on 2004-11-29
Last Modified: 2012-05-05
I'm trying to find out how to search through a folder on a server for occurences of a specific file. I have a folder with a load of files and corresponding metadata xml files. I want to be able to search through this folder and extract certain info from the metadata. I'm fine with the extraction of the xml, but need to know how to search through a folder. The files are all called imsmanifest.xml.

As always, any help is greatly appreciated.

Question by:applejuice
    1 Comment
    LVL 1

    Accepted Solution

    Here is how to do it-

    Say the directory is called "c:\files"

    class MyFilter implements FilenameFilter
          public boolean accept(File file, String name)
                return name.equalsIgnoreCase("imsmanifest.xml");
    File dir = new File("c:\\files");
    File [] lst = dir.listFiles(new MyFilter());

    This returns an array of Files matching your criteria.  If you need to do this in a web app relative to the context root you can get the context root with request.getContextPath() to get the base directory of the web app;


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
    Great sound, comfort and fit, excellent build quality, versatility, compatibility. These are just some of the many reasons for choosing a headset from Sennheiser.
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    760 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

    11 Experts available now in Live!

    Get 1:1 Help Now