public static File[] listFiles(final File aDir, final FilenameFilter aFilter, final boolean aDeepListing,
            final String... aIgnoreList) throws FileNotFoundException {
        if (!aDir.exists()) {
            throw new FileNotFoundException(aDir.getAbsolutePath());
        }

        if (aDir.isFile()) {
            if (aFilter.accept(aDir.getParentFile(), aDir.getName())) {
                return new File[] { aDir };
            } else {
                return new File[0];
            }
        }

        if (!aDeepListing) {
            return aDir.listFiles(aFilter);
        } else {
            final ArrayList<File> fileList = new ArrayList<>();
            final String[] ignoreList;

            if (aIgnoreList == null) {
                ignoreList = new String[0];
            } else {
                ignoreList = aIgnoreList;
            }

            for (final File file : aDir.listFiles()) {
                final String fileName = file.getName();

                if (aFilter.accept(aDir, fileName)) {
                    LOGGER.debug(MessageCodes.UTIL_010, file);
                    fileList.add(file);
                }

                if (file.isDirectory() && Arrays.binarySearch(ignoreList, fileName) < 0) {
                    final File[] files;

                    LOGGER.debug(MessageCodes.UTIL_011, file);
                    files = listFiles(file, aFilter, aDeepListing);
                    fileList.addAll(Arrays.asList(files));
                }

            }

            return fileList.toArray(new File[0]);
        }
    }
public static File [ ] listFiles ( final File aDir , final FilenameFilter aFilter , final boolean aDeepListing , final String ... aIgnoreList ) throws FileNotFoundException { if ( ! aDir . exists ( ) ) { throw new FileNotFoundException ( aDir . getAbsolutePath ( ) ) ; } if ( aDir . isFile ( ) ) { if ( aFilter . accept ( aDir . getParentFile ( ) , aDir . getName ( ) ) ) { return new File [ ] { aDir } ; } else { return new File [ 0 ] ; } } if ( ! aDeepListing ) { return aDir . listFiles ( aFilter ) ; } else { final ArrayList < File > fileList = new ArrayList < > ( ) ; final String [ ] ignoreList ; if ( aIgnoreList == null ) { ignoreList = new String [ 0 ] ; } else { ignoreList = aIgnoreList ; } for ( final File file : aDir . listFiles ( ) ) { final String fileName = file . getName ( ) ; if ( aFilter . accept ( aDir , fileName ) ) { LOGGER . debug ( MessageCodes . UTIL_010 , file ) ; fileList . add ( file ) ; } if ( file . isDirectory ( ) && Arrays . binarySearch ( ignoreList , fileName ) < 0 ) { final File [ ] files ; LOGGER . debug ( MessageCodes . UTIL_011 , file ) ; files = listFiles ( file , aFilter , aDeepListing ) ; fileList . addAll ( Arrays . asList ( files ) ) ; } } return fileList . toArray ( new File [ 0 ] ) ; } }
An array of all the files in the supplied directory that match the supplied <code>FilenameFilter</code>.
Directories that match the supplied ignore list will not be included in the result.

@param aDir A directory from which a file listing should be returned
@param aFilter A file name filter which returned files should match
@param aDeepListing Whether we should descend through subdirectories
@param aIgnoreList Directory names that should be ignored in the list.
@return An array of matching files
@throws FileNotFoundException If the supplied directory doesn't exist