@ SuppressWarnings ( "MagicNumber" ) protected Set < File > retrieveMatchingFiles ( File rootDir , String pattern ) throws IOException { if ( ! rootDir . exists ( ) ) { // Silently skip non-existing directories. return Collections . emptySet ( ) ; } if ( ! rootDir . isDirectory ( ) ) { // Complain louder if it exists but is no directory. return Collections . emptySet ( ) ; } if ( ! rootDir . canRead ( ) ) { return Collections . emptySet ( ) ; } String fullPattern = rootDir . getAbsolutePath ( ) . replace ( File . separator , "/" ) ; if ( ! pattern . startsWith ( "/" ) ) { fullPattern += "/" ; } fullPattern = fullPattern + pattern . replace ( File . separator , "/" ) ; Set < File > result = new LinkedHashSet < File > ( 8 ) ; doRetrieveMatchingFiles ( fullPattern , rootDir , result ) ; return result ; }
Retrieve files that match the given path pattern checking the given directory and its subdirectories .