com.mindprod.commandline
Class CommandLine

java.lang.Object
  extended by com.mindprod.commandline.CommandLine
All Implemented Interfaces:
java.lang.Iterable<java.io.File>

public final class CommandLine
extends java.lang.Object
implements java.lang.Iterable<java.io.File>

Process the command line passed to main to find all the files and directories mentioned on it.

They have he form: file.txt \mydir aRelativedir/subdir *.* The -s option means, include subdirectories of any mentioned directories thereafter everything is relative to the current directory, not to what preceeded on the line.

The -q (quiet) option means suppress listing of file processed.

Since:
2003-03-06
Version:
2.5 2009-02-28 - CommandLine now uses considerably less RAM by caching the list of files on disk. You no longer need specify estimatedFiles. Split off into its own package.
Author:
Roedy Green, Canadian Mind Products

Field Summary
static java.lang.String VERSION_STRING
          embedded version string.
 
Constructor Summary
CommandLine(java.lang.String[] args, java.io.FilenameFilter dirFilter, java.io.FilenameFilter fileFilter)
          constructor.
 
Method Summary
 boolean isQuiet()
          Return true if should suppress some output.
 java.util.Iterator<java.io.File> iterator()
          iterator over all files mentioned on the command line, expanded
static void main(java.lang.String[] args)
          TEST harness.
 int size()
          how many files hawe been collected?
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERSION_STRING

public static final java.lang.String VERSION_STRING
embedded version string.

See Also:
Constant Field Values
Constructor Detail

CommandLine

public CommandLine(java.lang.String[] args,
                   java.io.FilenameFilter dirFilter,
                   java.io.FilenameFilter fileFilter)
constructor.

Parameters:
args - arguments as they were passed to main, or any similar array of strings. Directory names, file names, "*.*", -s, -q, result of command line expansion of wildcards to indivdual files. Any null or empty args will be ignored. This allows you to process some args yourself then nullify them so CommandLine will ignore them.
dirFilter - a FileFilter to weed out any directories you don't want. It's accept method should return true for good directories. It should accept directories and reject files. No file will be accepted unless the directory it in is passes this muster.
fileFilter - FilenameFilter to weed out files you don't want. It's accept method should return true for any files you want. It should accept files and reject directories. No file will be accepted unless it passes this muster, even if specifically named. single filenames, directory names, dot, dot dot. If you use wildcards such as *.* a*.* abc?.html they expanded BY THE JAVA RUNTIME, to a list of directories and files. This is rarely what you want. *.* is effectively a one deep recursion into all directories, even without -s!! "*.*" however, will be treated like . The problem is, CommandLine can't tell apart a list of directories and files you want processed, from one Windows expanded from *.* or h*.*. Using an extension, on your wildcard e.g. *.html will tend to keep directories out. It then returns the files in the form of an Iterator to feed you the File objects, (not the File names), one by one. -s does subdirs as well for rest of dirs on line.
Method Detail

isQuiet

public boolean isQuiet()
Return true if should suppress some output.

Returns:
true if -q (quiet) option detected on command line.

iterator

public java.util.Iterator<java.io.File> iterator()
iterator over all files mentioned on the command line, expanded

Specified by:
iterator in interface java.lang.Iterable<java.io.File>
Returns:
simple iterator over all files, producing File objects of all the filenames mentioned on the command line, directly or indirectly. In same order as mentioned on command line.

single filenames, directory names, dot, dot dot. If you use wildcards such as *.* a*.* abc?.html they expanded BY THE JAVA RUNTIME, to a list of directories and files. This is rarely what you want. *.* is effectively a one deep recursion into all directories, even without -s!! "*.*" however, will be treated like . The problem is, CommandLine can't tell apart a list of directories and files you want processed, from one Windows expanded from *.* or h*.*. Using an extension, on your wildcard e.g. *.html will tend to keep directories out. It then returns the files in the form of an Iterator to feed you the File objects, (not the File name Strings), one by one. -s does subdirs as well for rest of dirs on line.


size

public int size()
how many files hawe been collected?

Returns:
count of files in the collection

main

public static void main(java.lang.String[] args)
TEST harness.

Parameters:
args - not used.