athanach
12-04-2007, 05:30 PM
i want to find and take all the files from a directory but from the subdirectories
i use the program below but i t gives me the files from the directory i give only no the subdirectories.
Any help for taking and the files from subdirectories???
import java.io.File;
import java.io.FilenameFilter;
import java.lang.String;
import java.lang.Exception;
import javax.swing.filechooser.FileFilter;
public class filesFinder {
/** Creates a new instance of fileFinder */
public void Finder(File dir) {
FilenameFilter filter = new FilenameFilter() {
public boolean accept(File dir, String name) {
return !name.endsWith(".meta");
}
};
String[] files = dir.list(filter);
//File[] files = dir.listFiles();
//files = dir.listFiles();
if (files == null) {
// Either dir does not exist or is not a directory
} else {
for (int i=0; i<files.length; i++) {
// Get filename of file or directory
String filename = files[i];
System.out.println(filename);
}
}
}
public static void main(String[] args) {
File dir=new File("sas");
filesFinder g=new filesFinder();
g.Finder(dir);
}
}
i use the program below but i t gives me the files from the directory i give only no the subdirectories.
Any help for taking and the files from subdirectories???
import java.io.File;
import java.io.FilenameFilter;
import java.lang.String;
import java.lang.Exception;
import javax.swing.filechooser.FileFilter;
public class filesFinder {
/** Creates a new instance of fileFinder */
public void Finder(File dir) {
FilenameFilter filter = new FilenameFilter() {
public boolean accept(File dir, String name) {
return !name.endsWith(".meta");
}
};
String[] files = dir.list(filter);
//File[] files = dir.listFiles();
//files = dir.listFiles();
if (files == null) {
// Either dir does not exist or is not a directory
} else {
for (int i=0; i<files.length; i++) {
// Get filename of file or directory
String filename = files[i];
System.out.println(filename);
}
}
}
public static void main(String[] args) {
File dir=new File("sas");
filesFinder g=new filesFinder();
g.Finder(dir);
}
}