import javax.imageio.*; import java.awt.image.*; import java.awt.*; import java.security.NoSuchAlgorithmException; import java.security.MessageDigest; import java.lang.reflect.*; import java.net.*; import java.io.*; import javax.swing.*; import java.util.regex.*; import java.util.List; import java.util.zip.*; import java.util.*; public class main { static String programID; static String searchFor; static int count; public static void main(String[] args) throws Exception { if (args.length == 0) { print("I search for files under the current directory."); print("Syntax: " + programID + " filetosearch"); } searchFor = args[0]; scan("."); if (count == 0) print("No results."); } static void scan(String file) { scan(new File(file)); } static String makeSearchPattern(String pat) { return pat.replace(".", "\\.").replace("*", ".*"); // rough... } static boolean match(String pat, File f) { return Pattern.compile(makeSearchPattern(pat), Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE).matcher(f.getName()).matches(); } static void scan(File f) { if (match(searchFor, f)) { print("Found " + (f.isFile() ? "file" : "dir") + ": " + f.getPath()); ++count; } if (f.isDirectory()) { File[] l = f.listFiles(); if (l != null) for (File x : l) scan(x); } } static void print() { System.out.println(); } static void print(Object o) { System.out.println(o); } }