Using class PathPattern one can list files using wildcards(* and ?) much likely doing it in a shell prompt.
For example, "*.txt" is a pattern for txt files in a current directory, and "c:/user/dir/*"
lists all in a "c:/user/dir" directory. Note that PathPattern makes no difference between object types(files, directories, links, etc).
To run an example, type:
java -cp .;[path to jregex.jar] List "some path with wildcards"
The sample session:
java -cp .;../lib/jregex.jar List "d:\Opera\*.txt"
Listing directory d:\Opera
Install.txt
License.txt
lngcode.txt
3 files found
Source:
import jregex.util.io.*;
public class List{
public static void main(String[] args){
if(args.length<1){
usage();
return;
}
PathPattern pp=new PathPattern(args[0]);
System.out.println("Listing directory "+pp.directory());
String[] files=pp.list();
for(int i=0;i<files.length;i++){
System.out.println(files[i]);
}
System.out.println();
System.out.println(files.length+" files found");
}
static void usage(){
System.out.println("Usage:");
System.out.println("java -cp .;[path to jregex.jar] List \"PATH\"");
}
}