import java.sql.*; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.List; import java.io.*; class FileFinder { static String indirectory = "."; static String filterRegExp = ".*"; static String date_time = "01.01.00:00:00"; static boolean bFiles = true; static boolean bDirectories = true; static final SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yy HH:mm"); static final SimpleDateFormat inDateFormat = new SimpleDateFormat("dd.MM.yy:HH:mm"); static final String newLine = "rn"; //////////////////////////////////////////////////// public static void usage() { System.err.println( "Usage: FilesSince <directory> <"filterRegExp"> [-t <date_time>] [-(f|d|b)]"); System.err.println( "Options:"); System.err.println( " filterRegExp: Like .* (Everything) or .*\.java (Every file with .java extension)"); System.err.println( " Don't forget to surround the regular expression with quotation marks"); System.err.println( " -t <Minimum file time. Format: dd.mm.yy:hh:mm>"); System.err.println( " -f List files"); System.err.println( " -d List directories"); System.err.println( " -b List both files and directories"); } //////////////////////////////////////////////////// static private boolean readCommandLine( String args[]) { int i = 0; int argsUsed = 0; if( args.length < 3) { usage(); return false; } while( i < args.length) { if (args[i].charAt(0) == '-') { switch( args[i].charAt(1)) { case 'h': case '?': usage(); return false; case 't': i++; date_time = args[i]; return true; case 'D': bDirectories = true; return true; case 'F': bFiles = true; return true; case 'B': bFiles = true; bDirectories = true; return true; default: System.out.println( "*** Unknown option:" + args[argsUsed]); usage(); return false; } } else { if( argsUsed==0) indirectory = args[i]; else if ( argsUsed==1) filterRegExp = args[i]; else { System.err.println( "Unknown option:" + args[i]); usage(); return false; } argsUsed++; } i++; } return true; } //////////////////////////////////////////////////// static boolean initialize() { return true; } /* static void recurse( Vector vecFiles, String actPath, long minDate) throws IOException { String pathname; File f = new File( actPath); File[] a_f = f.listFiles(); for( int i=0; i<a_f.length; i++) { pathname = a_f[i].getCanonicalPath(); if( a_f[i].isDirectory()) { recurse( vecFiles, pathname, minDate); } else { if( a_f[i].lastModified() > minDate ) { vecFiles.add( a_f[i]); } } } } */ /**************************************************************************** * main *****************************************************************************/ public static void main (String args []) throws SQLException { if (!readCommandLine( args)) { return; //>>>>>>>>>>> } if( indirectory == null) { usage(); return; //>>>>>>>>>>> } final long minDate; try { minDate = inDateFormat.parse( date_time).getTime(); } catch (ParseException e1) { e1.printStackTrace(); usage(); return; //>>>>>>>>>>> } List files; try { indirectory = new File( indirectory).getCanonicalPath(); files = FileUtils.getFileListing( new File( indirectory), filterRegExp, true, false); } catch (FileNotFoundException e) { e.printStackTrace(); return; } catch (IOException e) { e.printStackTrace(); return; } // print out all file names, and display the order of File.compareTo for( int i=0; i<files.size(); i++) { File file = (File) files.get(i); if( file.lastModified() > minDate) { System.out.println( file); } } /* Vector v = new Vector(); try { recurse( v, indirectory, minDate); } catch (IOException e1) { e1.printStackTrace(); return; } for( int i=0; i<v.size(); i++) { // System.out.println( ((File)v.elementAt(i)).getCanonicalPath()); System.out.println( ((File)v.elementAt(i)).getPath()); } */ } } import java.sql.*; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.List; import java.io.*; class FileFinder { static String indirectory = "."; static String filterRegExp = ".*"; static String date_time = "01.01.00:00:00"; static boolean bFiles = true; static boolean bDirectories = true; static final SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yy HH:mm"); static final SimpleDateFormat inDateFormat = new SimpleDateFormat("dd.MM.yy:HH:mm"); static final String newLine = "rn"; //////////////////////////////////////////////////// public static void usage() { System.err.println( "Usage: FilesSince <directory> <"filterRegExp"> [-t <date_time>] [-(f|d|b)]"); System.err.println( "Options:"); System.err.println( " filterRegExp: Like .* (Everything) or .*\.java (Every file with .java extension)"); System.err.println( " Don't forget to surround the regular expression with quotation marks"); System.err.println( " -t <Minimum file time. Format: dd.mm.yy:hh:mm>"); System.err.println( " -f List files"); System.err.println( " -d List directories"); System.err.println( " -b List both files and directories"); } //////////////////////////////////////////////////// static private boolean readCommandLine( String args[]) { int i = 0; int argsUsed = 0; if( args.length < 3) { usage(); return false; } while( i < args.length) { if (args[i].charAt(0) == '-') { switch( args[i].charAt(1)) { case 'h': case '?': usage(); return false; case 't': i++; date_time = args[i]; return true; case 'D': bDirectories = true; return true; case 'F': bFiles = true; return true; case 'B': bFiles = true; bDirectories = true; return true; default: System.out.println( "*** Unknown option:" + args[argsUsed]); usage(); return false; } } else { if( argsUsed==0) indirectory = args[i]; else if ( argsUsed==1) filterRegExp = args[i]; else { System.err.println( "Unknown option:" + args[i]); usage(); return false; } argsUsed++; } i++; } return true; } //////////////////////////////////////////////////// static boolean initialize() { return true; } /* static void recurse( Vector vecFiles, String actPath, long minDate) throws IOException { String pathname; File f = new File( actPath); File[] a_f = f.listFiles(); for( int i=0; i<a_f.length; i++) { pathname = a_f[i].getCanonicalPath(); if( a_f[i].isDirectory()) { recurse( vecFiles, pathname, minDate); } else { if( a_f[i].lastModified() > minDate ) { vecFiles.add( a_f[i]); } } } } */ /**************************************************************************** * main *****************************************************************************/ public static void main (String args []) throws SQLException { if (!readCommandLine( args)) { return; //>>>>>>>>>>> } if( indirectory == null) { usage(); return; //>>>>>>>>>>> } final long minDate; try { minDate = inDateFormat.parse( date_time).getTime(); } catch (ParseException e1) { e1.printStackTrace(); usage(); return; //>>>>>>>>>>> } List files; try { indirectory = new File( indirectory).getCanonicalPath(); files = FileUtils.getFileListing( new File( indirectory), filterRegExp, true, false); } catch (FileNotFoundException e) { e.printStackTrace(); return; } catch (IOException e) { e.printStackTrace(); return; } // print out all file names, and display the order of File.compareTo for( int i=0; i<files.size(); i++) { File file = (File) files.get(i); if( file.lastModified() > minDate) { System.out.println( file); } } /* Vector v = new Vector(); try { recurse( v, indirectory, minDate); } catch (IOException e1) { e1.printStackTrace(); return; } for( int i=0; i<v.size(); i++) { // System.out.println( ((File)v.elementAt(i)).getCanonicalPath()); System.out.println( ((File)v.elementAt(i)).getPath()); } */ } }