FileDocCategorySizeDatePackage
Find.javaAPI DocExample1780Sun Feb 08 21:33:48 GMT 2004None

Find

public class Find extends Object
Find - find files by name, size, or other criteria. Non-GUI version.
author
Ian Darwin, http://www.darwinsys.com/
version
$Id: Find.java,v 1.6 2004/02/09 03:33:47 ian Exp $

Fields Summary
protected FindFilter
filter
Constructors Summary
Methods Summary
private static voiddoFile(java.io.File f)
doFile - process one regular file.

		System.out.println("f " + f.getPath());
	
private voiddoName(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 voidmain(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 voidusage()


	    
		System.err.println(
			"Usage: Find [-n namefilter][-s sizefilter][dir...]");
		System.exit(1);