Skip to content

Commit 45da38f

Browse files
author
Niall Pemberton
committed
IO-176 Add a callback method for filtering directory contents - requested by David Felsenthal
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/io/trunk@721635 13f79535-47bb-0310-9956-ffa450edef68
1 parent f992185 commit 45da38f

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

src/java/org/apache/commons/io/DirectoryWalker.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ private void walk(File directory, int depth, Collection<?> results) throws IOExc
355355
if (depthLimit < 0 || childDepth <= depthLimit) {
356356
checkIfCancelled(directory, depth, results);
357357
File[] childFiles = (filter == null ? directory.listFiles() : directory.listFiles(filter));
358+
childFiles = filterDirectoryContents(directory, depth, childFiles);
358359
if (childFiles == null) {
359360
handleRestricted(directory, childDepth, results);
360361
} else {
@@ -504,6 +505,20 @@ protected void handleDirectoryStart(File directory, int depth, Collection<?> res
504505
// do nothing - overridable by subclass
505506
}
506507

508+
/**
509+
* Overridable callback method invoked with the contents of each directory.
510+
* <p>
511+
* This implementation returns the files unchanged
512+
*
513+
* @param directory the current directory being processed
514+
* @param depth the current directory level (starting directory = 0)
515+
* @param files the files (possibly filtered) in the directory
516+
* @throws IOException if an I/O Error occurs
517+
*/
518+
protected File[] filterDirectoryContents(File directory, int depth, File[] files) throws IOException {
519+
return files;
520+
}
521+
507522
/**
508523
* Overridable callback method invoked for each (non-directory) file.
509524
* <p>

0 commit comments

Comments
 (0)