com.gargoylesoftware.base.util
Class DirectoryWalker

java.lang.Object
  extended bycom.gargoylesoftware.base.util.DirectoryWalker

public class DirectoryWalker
extends Object

A class to walk through the directory structure from a given starting point and return either files or directories or both.

The following sample gets all java files.

 final FileFilter filter = new FileFilter() {
     public boolean accept( final File file ) {
         return file.getName().endsWith(".java");
     }
 };

 final DirectoryWalker directoryWalker = new DirectoryWalker(".");
 final Collection files = directoryWalker.getFiles(filter);
 

Version:
$Revision: 1.6 $
Author:
Mike Bowler

Constructor Summary
DirectoryWalker(String startingDirectory)
          Create an instance
 
Method Summary
 Collection getDirectories(FileFilter filter)
          Walk through the directory structure and return a collection containing all those directories for which the filter returns true
 Collection getFiles(FileFilter filter)
          Walk through the directory structure and return a collection containing all those files for which the filter returns true
 Collection getFilesAndDirectories(FileFilter filter)
          Walk through the directory structure and return a collection containing all those files and directories for which the filter returns true
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DirectoryWalker

public DirectoryWalker(String startingDirectory)
Create an instance

Parameters:
startingDirectory - the directory to start in
Method Detail

getFiles

public Collection getFiles(FileFilter filter)
Walk through the directory structure and return a collection containing all those files for which the filter returns true

Parameters:
filter - An object to determine whether or not to include this file in the returned collection
Returns:
A collection of File objects

getDirectories

public Collection getDirectories(FileFilter filter)
Walk through the directory structure and return a collection containing all those directories for which the filter returns true

Parameters:
filter - An object to determine whether or not to include this directory in the returned collection
Returns:
A collection of File objects

getFilesAndDirectories

public Collection getFilesAndDirectories(FileFilter filter)
Walk through the directory structure and return a collection containing all those files and directories for which the filter returns true

Parameters:
filter - An object to determine whether or not to include this file/directory in the returned collection
Returns:
A collection of File objects


Copyright © 1998-2005 Gargoyle Software Inc.. All Rights Reserved.