private static ArrayList < File > getContentsInDirectoryTree ( File directory , FileFilterRuleSet ruleSet , boolean returnFiles , boolean returnDirs ) { ArrayList < File > result = new ArrayList < File > ( ) ; if ( directory != null && directory . exists ( ) && directory . isDirectory ( ) ) { File [ ] files = directory . listFiles ( ) ; if ( files != null ) { for ( int i = 0 ; i < files . length ; i ++ ) { if ( files [ i ] . isDirectory ( ) ) { if ( returnDirs && ruleSet . fileMatchesRules ( files [ i ] ) ) { result . add ( files [ i ] ) ; } result . addAll ( getContentsInDirectoryTree ( files [ i ] , ruleSet , returnFiles , returnDirs ) ) ; } else if ( returnFiles && ruleSet . fileMatchesRules ( files [ i ] ) ) { result . add ( files [ i ] ) ; } } } } return result ; }
Retrieves contents from a directory and its subdirectories matching a given rule set .