Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Search for a directory by its name only

 
garfild Baram
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9300
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
garfild Baram
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9300
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's several. Have a look at the API documentation and look for the various list methods.
 
garfild Baram
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Joe, I have found the solution for that :-)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic