Perry Smith
Java Questions & Answers
Home /
Java Q & A Page 2 /
Java Q & A Archive Main Page
Search for a file?
Sunday, 06-Dec-98 21:28:16
209.86.170.112 writes:
Hi. I'm a newbie to Java. Could someone point me in the right direction. I am trying to
search a drive for a file the user provided. I've read about file constructors and file
methods, but I don't know how to find out where a file might be on the disk drive. I'm
not expecting an answer, just a little push. Thanks.
Phil Fausz@mindspring.com
Charles.Fausz@rhd.com
Phil
Response
Re: Search for a file?
Monday, 07-Dec-98 12:27:33
148.5.110.65 writes:
Phil,
The following will take you through all directories which should help you.
traverse(new String("c:\"));
void traverse(String aRoot)
{
File thePath = new File(aRoot);
String theNames = thePath.list(); //List of files in this dir
for (int i=0; i < theNames .length; i++)
{
String theFullPathName = theRoot + File.separator + theNames [i];
thePath = new File(theFullPathName);
if (thePath.isDirectory())
{
String temp = thePath.getPath();
traverse(temp);
}
}
}
}
Scott_M2
Home /
Java Q & A Page 2 /
Java Q & A Archive Main Page