static private List < File > getFileListingLogs ( File aStartingDir ) throws Exception { List < File > result = new ArrayList < File > ( ) ; File [ ] logfiles = aStartingDir . listFiles ( new FileFilter ( ) { @ Override public boolean accept ( File pathname ) { return pathname . isFile ( ) ; } } ) ; List < File > logFilesList = Arrays . asList ( logfiles ) ; File [ ] allDirs = aStartingDir . listFiles ( new FileFilter ( ) { @ Override public boolean accept ( File pathname ) { return pathname . isDirectory ( ) ; } } ) ; for ( File file : logFilesList ) { if ( file . getName ( ) . equals ( "log.xml" ) ) { result . add ( file ) ; } } List < File > allDirsList = Arrays . asList ( allDirs ) ; Collections . sort ( allDirsList , new Comparator < File > ( ) { public int compare ( File o1 , File o2 ) { if ( o1 . lastModified ( ) > o2 . lastModified ( ) ) { return + 1 ; } else if ( o1 . lastModified ( ) < o2 . lastModified ( ) ) { return - 1 ; } else { return 0 ; } } } ) ; for ( File file : allDirsList ) { if ( ! file . isFile ( ) ) { List < File > deeperList = getFileListingLogs ( file ) ; result . addAll ( deeperList ) ; } } return result ; }
Get all log files and directories and make recursive call .