Findpublic class Find extends Object Find - find files by name, size, or other criteria. Non-GUI version. |
Fields Summary |
---|
protected FindFilter | filter |
Methods Summary |
---|
private static void | doFile(java.io.File f)doFile - process one regular file.
System.out.println("f " + f.getPath());
| private void | doName(java.lang.String s)doName - handle one filesystem object by name
Debug.println("flow", "doName(" + s + ")");
File f = new File(s);
if (!f.exists()) {
System.out.println(s + " does not exist");
return;
}
if (f.isFile())
doFile(f);
else if (f.isDirectory()) {
// System.out.println("d " + f.getPath());
String objects[] = f.list(filter);
for (int i=0; i<objects.length; i++)
doName(s + f.separator + objects[i]);
} else
System.err.println("Unknown type: " + s);
| public static void | main(java.lang.String[] args)Main program
Find finder = new Find();
GetOpt argHandler = new GetOpt("n:s:");
int c;
while ((c = argHandler.getopt(args)) != GetOpt.DONE) {
switch(c) {
case 'n": finder.filter.setNameFilter(argHandler.optarg()); break;
case 's": finder.filter.setSizeFilter(argHandler.optarg()); break;
default:
System.out.println("Got: " + c);
usage();
}
}
if (args.length == 0 || argHandler.getOptInd()-1 == args.length) {
finder.doName(".");
} else {
for (int i = argHandler.getOptInd()-1; i<args.length; i++)
finder.doName(args[i]);
}
| public static void | usage()
System.err.println(
"Usage: Find [-n namefilter][-s sizefilter][dir...]");
System.exit(1);
|
|