Searching directory and subdirectories ................

i have to search a given directory and its subdirectories, for the files having a part of string in their names.

e.g. i want to search all files in that directory and subdirectories having "12345" in their name.

i want algorithm help and also java specific help in this case?

Regards

[309 byte] By [@tifa] at [2007-11-26 17:15:01]
# 1

I've seen a couple of example java programs which do a recursive file search... one was a reasonable approximation of the unix find command... I fell over it whist searching for something else.

One thing though... a native compiled program will be substantially faster at this... it's heavy I/O stuff, and java's performance suffers a tad from it's (good) decision to divorce itself from the underlying O/S and it's services.

Keith.

corlettka at 2007-7-8 23:43:00 > top of Java-index,Java Essentials,New To Java...
# 2
should i use some thing like recursion r is there some more efficient way?
@tifa at 2007-7-8 23:43:01 > top of Java-index,Java Essentials,New To Java...
# 3

Hi,

if it can give you some help, i write this program to explore zip files in the same directory of it and give you an output of them files:

import java.util.*;

import java.util.zip.*;

import java.io.*;

public class ReadZip

{

public static void main(String [] a)

{

File dir=new File(".");

System.out.println("Apro la directory "+dir.getAbsolutePath());

File[] cont=dir.listFiles();

int MAX=cont.length;

for (int i = 0; i<MAX; i++)

{

String tmp=cont[i].getName();

if ((tmp.endsWith(".zip"))||(tmp.endsWith(".ZIP")))

{

// it is a file *.zip

System.out.println("Ho trovato "+tmp);

controllaZip(cont[i]);

};

}

}

public static void controllaZip(File f)

{

System.out.println("Contenuto del file "+f.getName());

ZipFile Zf;

try {Zf=new ZipFile(f);}

catch (ZipException e){Zf=null;}

catch (IOException e1){Zf=null;}

;

Enumeration files=Zf.entries();

while(files.hasMoreElements())

System.out.println(files.nextElement());

}

}

I hope that you it has been of help.

Goodbye

hawake

Message was edited by:

hawake>

hawakea at 2007-7-8 23:43:01 > top of Java-index,Java Essentials,New To Java...