
/**
 * DirectoryLister.java
 *This class list all the files which end in a specific string.  I stole this from some one, who stole
 *it from some where...
 * Created: May 20, 2004
 *
 * @author Nathan Stevens
 * @version 0.1 5/26/04
 */
 
 import java.io.*;
 import java.util.Vector;
 
 public class DirectoryLister {
   private Vector files;
   private int count = 0;
   
   // The main constructor
   public DirectoryLister() {
     files = new Vector(100, 25);
   }
   
   // Method to find a file with a specific ending using recursive calls
   public void listDirectory(File entry, String ending) {
     String filename;
     try {
       if(entry.isFile()) {
         filename = entry.getName();
         if(filename.endsWith(ending)) {
           count++;
           files.add(entry);
         }
       }
       else if(entry.isDirectory()) {
         String[] filenames = entry.list();
         if(filenames == null) {
           return;
         }
         for(int i = 0; i < filenames.length; i++) {
           File item = new File(entry.getPath(), filenames[i]);
           listDirectory(item, ending);
         }
       }
     }
     catch(Exception e) {
       System.err.println("Error: " + e);
     }
   }
   
   // Method to get the file list
   public File[] getFileList() {
     File[] filelist = new File[count];
     return (File[])files.toArray(filelist);
   }
 }//--DirectoryLister
