wood burning stoves 2.0*
The moose likes I/O and Streams and the fly likes Finding a folder or a file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Finding a folder or a file" Watch "Finding a folder or a file" New topic
Author

Finding a folder or a file

Kelly Harris
Greenhorn

Joined: Mar 27, 2002
Posts: 22
I have a need to be able to search a folder structure for a file or a folder. I looked at Class File. I could probably use this to find what I need but I am looking for a possibly better solution.
thanks
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
This might help:

change "/" for "C:\" if you're under windoze
hope it helps
Kelly Harris
Greenhorn

Joined: Mar 27, 2002
Posts: 22
Thanks Harold A. Gim´┐Żnez
I ended up
<blockquote><font size="1" face="Verdana, Arial">code:
<pre>
/** ------------------------------------------------------------
findFolder
find a specific folder in a path?
------------------------------------------------------------
input:
path:Starting path to search for folder
folder:The folder name to process.
@return
the full path to the specified folder w/o folder
------------------------------------------------------------ */
public String findFolder( String path, String folder)
{
String returnValue = null;
File f = new File(path);
String [] s;
s = f.list();
int counter;

// search this current folder before searchins sub folders
for (counter=0; counter < s.length; counter++)
{
if ( s[counter].compareToIgnoreCase( folder) == 0)
{
returnValue = path;
break;
} // if
//System.out.println( s [counter].toString());
} // for
// Search any sub folders.
if (returnValue == null)
for (counter=0; counter < s.length; counter++)
{
File test = new File( path + s[counter]);
if ( test.isDirectory() == true)
{
returnValue = findFolder( path + s[counter] + '\\', folder);
if (returnValue != null)
break;
} // if
//System.out.println( s [counter].toString());
} // for
return returnValue;
} // findFolder

</pre><hr>
</blockquote>
I was hoping that there was an already built in function to do a search. I am sure that I probably missed something.
Kelly Harris
Greenhorn

Joined: Mar 27, 2002
Posts: 22
Sorry all, I exepcted I could do some HTML code here. Oops.
 
wood burning stoves
 
subject: Finding a folder or a file
 
Similar Threads
How to load the resources outside WEB-INF?
Code from SCJP K&B Book won't compile
UPLOAD WAR File to Tomcat 5.5
symbolic link
writing an xml file to a shared folder