// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.io.*;

public class DirWithFilter {
    public static int countExtension(String dir, String ext) {
        File dirobj = new File(dir);
        String[] filelist = dirobj.list(new ExtensionCheck(ext));
        return filelist.length;
    }
    public static void main(String[] args) {
        System.out.println(countExtension("C:\\", ".java"));
        System.out.println(countExtension("C:\\", ".bat"));
    }
}

class ExtensionCheck implements FilenameFilter {
    private String ext;
    public ExtensionCheck(String ext) {
        this.ext = ext;
    }
    public boolean accept(File dir, String name) {
        return name.endsWith(ext);
    }
}
