import java.io.File; import java.io.FilenameFilter; public class ListFiles{ public static void main(String args[]){ File directory = new File(args[0]); for(File file : directory.listFiles(getRegexFilter(".*\\.xls"))){ System.out.println(file.getAbsolutePath()); } } private static FilenameFilter getRegexFilter(String regex) { final String regex_ = regex; return new FilenameFilter() { public boolean accept(File dir, String name) { return name.matches(regex_); } }; } }