Author: niallp Date: Fri Nov 28 21:05:59 2008 New Revision: 721635 URL: http://svn.apache.org/viewvc?rev=721635&view=rev Log: IO-176 Add a callback method for filtering directory contents - requested by David Felsenthal
Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/DirectoryWalker.java Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/DirectoryWalker.java URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/DirectoryWalker.java?rev=721635&r1=721634&r2=721635&view=diff ============================================================================== --- commons/proper/io/trunk/src/java/org/apache/commons/io/DirectoryWalker.java (original) +++ commons/proper/io/trunk/src/java/org/apache/commons/io/DirectoryWalker.java Fri Nov 28 21:05:59 2008 @@ -355,6 +355,7 @@ if (depthLimit < 0 || childDepth <= depthLimit) { checkIfCancelled(directory, depth, results); File[] childFiles = (filter == null ? directory.listFiles() : directory.listFiles(filter)); + childFiles = filterDirectoryContents(directory, depth, childFiles); if (childFiles == null) { handleRestricted(directory, childDepth, results); } else { @@ -505,6 +506,20 @@ } /** + * Overridable callback method invoked with the contents of each directory. + * <p> + * This implementation returns the files unchanged + * + * @param directory the current directory being processed + * @param depth the current directory level (starting directory = 0) + * @param files the files (possibly filtered) in the directory + * @throws IOException if an I/O Error occurs + */ + protected File[] filterDirectoryContents(File directory, int depth, File[] files) throws IOException { + return files; + } + + /** * Overridable callback method invoked for each (non-directory) file. * <p> * This implementation does nothing.