Re: Search for a file on hard drive?
Rafael <[email protected]>
| Newsgroups | gmane.comp.java.sun.servlet |
|---|---|
| Message-ID | <003d01c2be36$3276c0b0$4b01a8c0@hbtec071> |
Try this .....
--------------------------------------------------------------------------
import java.io.*;
class test_find
{
public static void main( String args[] )
{
if( args != null && args.length > 0 )
{
if( args[0] != null && args[1] != null)
{
if( findFile( new File( args[0] ), args[1] ) <= 0 )
{
System.out.println("File not found!");
}
}
else
{
System.out.println("Parameter not found!");
}
}
else
{
System.out.println("Parameter not found!");
}
}
public static int findFile( File pDir, String word )
{
int count = 0;
File[] arrFile = pDir.listFiles();
File tmp;
// First look into this folder
for (int i=0; i<arrFile.length; i++)
{
tmp = arrFile[i];
if ( tmp.getName().equalsIgnoreCase(word))
{
System.out.println(tmp);
count++;
}
}
//now look into sub folders
for (int i=0; i<arrFile.length; i++)
{
tmp = arrFile[i];
if( tmp.isDirectory() )
{
findFile( tmp, word );
}
}
return count;
}
}
----------------------------------------------------------------------------
--
Rafael Schleuss
Java Developer
[email protected]