Re: Search for a file on hard drive?

Ali Chadorbaf <[email protected]>
Newsgroups gmane.comp.java.sun.servlet
Message-ID <[email protected]>
Thanks all you guys. That's all i wantted.
The only thing is , the directory that i want to search is a subdirectory of
the current directory. Since i don't know the current directory( i don't know
where the application installed) so i need to know how could i get the current
directory ?


--- Rafael Schleuss <[email protected]> wrote:
>
> Try this .....
>
>
----------------------------------------------------------------------------------
> import java.io.*;
>
> class teste
> {
>    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;
>   }
> }
>
>
----------------------------------------------------------------------------------
>
>
> On Thu, 2003-04-17 at 02:05, Ramchandra wrote:
>
> > Hi,
> >
> >         There is no perticular method for searching the files in folders
> and
> > the sub forlders of it.
> >
> >         Usualy all programmers start searching from a perticular folder and
> > then start searching into its sub folders.       For doing the same
> > programmaticaly in Java U hv to give the following codec within a loop.
> > Use isFile() method of File class which returns "True" if the name
> specified
> > is a file and "False" if it is a folder....    If it is false just replace
> > the Folder name in File classe's constructor with the name specified and so
> > on.....     It all depends on how do U manage the loop...    The code is as
> > follow;
> >
> >        File file = new File("C:\\");
> >        String [] files = file.list();
> >        for (int i=0; i<files.length; i++) {
> >            if (files[i].endsWith(".exe")) {
> >                 System.out.println(files[i]);
> >            }
> >        }
> >
> > Cheers,
> > Ramachandra B.S.
> > Software Engineer
> > Conpudyne Winfosystems Ltd.(CWLGLOBAL)
> > Bangalore.
> >
> > ___________________________________________________________________________
> > To unsubscribe, send email to [email protected] and include in the body
> > of the message "signoff SERVLET-INTEREST".
> >
> > Archives: http://archives.java.sun.com/archives/servlet-interest.html
> > Resources: http://java.sun.com/products/servlet/external-resources.html
> > LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
> --
> Rafael Schleuss
> Java Developer
> [email protected]
>


__________________________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo
http://search.yahoo.com

___________________________________________________________________________
To unsubscribe, send email to [email protected] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.