• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Finding a folder or a file

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This might help:

change "/" for "C:\" if you're under windoze
hope it helps
 
Kelly Harris
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry all, I exepcted I could do some HTML code here. Oops.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic