Meaningless Drivel is fun!*
The moose likes I/O and Streams and the fly likes Search for a directory by its name only Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Search for a directory by its name only" Watch "Search for a directory by its name only" New topic
Author

Search for a directory by its name only

garfild Baram
Ranch Hand

Joined: Mar 24, 2003
Posts: 60
Hi,
Till now I was using the following to find the existance of "myDirectory" directory:

File currentDir = new File("c:" + File.separator + myDirecory");
boolean dirExist = currentDir.isDirectory();

I would like to search myDirectoryon in my whole computer with just specifying its name (without a path).
Can I do that?

Thanks

Yossi
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8935
    
    9

Yes. File has methods to determine the root drives. File also has methods to list out the contents of a particular file and whether the child is a file or a directory. If it is a directory, search it. If it is a file, compare its name to the one you want.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
garfild Baram
Ranch Hand

Joined: Mar 24, 2003
Posts: 60
yes, you are right, we have the File[] ff = File.listRoots();
The question here is how to iterate all root folders for a search of my specific folder?
What is the function that lists the content of folders in each root?
thanks man
Yossi
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8935
    
    9

There's several. Have a look at the API documentation and look for the various list methods.
garfild Baram
Ranch Hand

Joined: Mar 24, 2003
Posts: 60
thanks Joe, I have found the solution for that :-)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Search for a directory by its name only