|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.ccg.util.FilenameFilterWild
public class FilenameFilterWild
Class to get a list of file names using wild cards. This class is used to allow one to get a listing of filenames matching (or not matching) a criteria similar to the standard wild cards used by Unix, Windows, and OS/2 type systems when listing files. For example, one could use this class to get a listing of all the "*.java" files in a particular directory. This class can be passed as an argument to the java.io.File.list function, or one can use the static list member declared in this class to automatically generate a listing of file names.
// Get list of java & html files
String[] files = FilenameFilterWild.list("ccg\\util\\*.java;*.html");
// get list by constructing matches
FilenameFilterWild ffw = new FilenameFilterWild();
// Matches Fullname.java, FilenameWild.java,...
ffw.addWildString("F?l*name*.java");
ffw.addWildString("*.c;*.h"); // Matches C source files
java.io.File dir = new java.io.File(".");
String[] files = dir.list(ffw);
ffw.setShouldMatch(false); // now get files which don't match
String[] rest = dir.list(ffw);
FilenameFilter,
File.list(java.io.FilenameFilter),
list(java.lang.String)| Constructor Summary | |
|---|---|
FilenameFilterWild()
Constructor for the FilenameFilterWild class. |
|
| Method Summary | |
|---|---|
boolean |
accept(File f,
String n)
Determine if a file should be included based on matching rules. |
void |
addWildString(String ws)
Add more matching rules. |
static String[] |
list(String matching)
Get a list of files matching a specified criteria (handy). |
void |
setShouldMatch(boolean f)
Toggle whether to get files which match or which do NOT match. |
String |
toString()
Get current matching rules in String form. |
static boolean |
wildCompare(String wildString,
String name)
Determine if a string matches a "wild" string (handy). |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public FilenameFilterWild()
| Method Detail |
|---|
public boolean accept(File f,
String n)
accept in interface FilenameFilterf - File to be checkedn - Name of the file to be checked (this is compared against the
wild strings)
list(java.lang.String),
File.list(java.io.FilenameFilter)public void addWildString(String ws)
For example: "*.cc" would match against files like: "Fred.cc" and "Mary.cc", but not against files like: "Frank.cc.old" or "Mary.hh". The wild strings can be complex, for example: "Fr?n*k*" would match "Franky" and "Fran.kc", but not "Fred.k".
ws - Wild string(s) to add - semicolons must be used to separate
the strings if more than one is included (typically something
like: "*.c" or "*.h;*.c")accept(java.io.File, java.lang.String),
wildCompare(java.lang.String, java.lang.String)public static String[] list(String matching)
For example: list("/opt/include/*.hh;*.h") would return a list of all C++ and C header files in the "/opt/include" directory. list("F*name*.java") would return a list of all files matching "F*name*.java" in the current directory.
matching - This is the string used to specify what files you are looking
for. It may contain optional path information at the start (if
omitted, the current directory will be searched), and one or
more wild strings to match filenames against. The following
are all valid examples: "*.java",
"/o/opt/java/ccg/util/FilenameFilterWild.java;*.class;F*.htm*",
and "c:\winnt\*.exe;*.com". You can pass null, but you'll get
null back.
accept(java.io.File, java.lang.String),
Example Programpublic final void setShouldMatch(boolean f)
f - Set to true if you want this object to be used to return a
list of files which match the criteria specified (this is the
default behaviour). Set to false if you want this object to be
used to return a list of files which do not match the criteria
specified.accept(java.io.File, java.lang.String)public String toString()
toString in class Object
public static boolean wildCompare(String wildString,
String name)
For example: "*.cc" would match against strings like: "Fred.cc" and "Mary.cc", but not against strings like: "Frank.cc.old" or "Mary.hh". The wild strings can be complex, for example: "Fr?n*k*" would match "Franky" and "Fran.kc", but not "Fred.k".
wildString - String which can contain the wildcard characters ('*' and '?')name - String to see if it matches against the wildString
accept(java.io.File, java.lang.String)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||