1 package org.incava.io; 2 3 import java.io.*; 4 import java.util.ArrayList ; 5 import java.util.List ; 6 7 8 11 public class Find 12 { 13 18 public static void getFileList(List fileList, String name, final String suffix) 19 { 20 try { 21 File fd = new File(name); 22 if (fd.isDirectory()) { 23 tr.Ace.log("processing directory"); 24 String [] contents = fd.list(new FilenameFilter() { 25 public boolean accept(File dir, String nm) { 26 File f = new File(dir, nm); 27 return f.isDirectory() || (f.isFile() && nm.endsWith(suffix)); 28 } 29 }); 30 for (int ci = 0; contents != null && ci < contents.length; ++ci) { 31 getFileList(fileList, name + File.separator + contents[ci], suffix); 32 } 33 } 34 else if (fd.isFile()) { 35 tr.Ace.log("adding: " + fd); 36 fileList.add(fd.getCanonicalPath()); 37 } 38 else { 39 System.err.println(name + " not found."); 40 } 41 } 42 catch (FileNotFoundException e) { 43 System.err.println("File " + name + " not found."); 44 } 45 catch (IOException e) { 46 System.err.println("Error opening " + name + ": " + e); 47 } 48 } 49 50 56 public static String [] getFileList(String [] names, String suffix) 57 { 58 List fileList = new ArrayList (); 59 for (int i = 0; i < names.length; ++i) { 60 getFileList(fileList, names[i], suffix); 61 } 62 String [] fileNames = (String [])fileList.toArray(new String [0]); 63 return fileNames; 64 } 65 66 } 67 | Popular Tags |