[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 246
  • Last Modified:

Searching a folder for specific files

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.

1 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;


Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now