File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Search For File Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Search For File " Watch "Search For File " New topic

Search For File

kayanaat sidiqui
Ranch Hand

Joined: Sep 04, 2008
Posts: 122

Following is the directory structure in which i need to llok for the files.

I need to search for the files which exist only in "FOL".

As you can notice easily that it's not necessary that every directory must contain "FOL".

What i need just take input as file name from user and look for those file in FOL.
What we already know that root path of above directory that is path where above directory exist.

Is there any better and faster way to do this?


Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46320
Please edit your post to add code tags; it will preserve the spaces in your diagram.

I have only ever sen it done recursively, using the methods of the File class. Remember that File can refer to a directory as well as an ordinary file, so you can get an array of contained files in a directory. You can check whether the name of a file ends with "FOL" using the methods of the String class, if necessary. You can also put a filter on a search.
David Newton

Joined: Sep 29, 2008
Posts: 12617

Better or faster way than what?
I agree. Here's the link:
subject: Search For File
jQuery in Action, 3rd edition