1. /*
  2. * Copyright 2002-2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.apache.commons.io.filefilter;
  17. import java.io.File;
  18. /**
  19. * This filter accepts <code>File</code>s that are directories.
  20. * <p>
  21. * For example, here is how to print out a list of the
  22. * current directory's subdirectories:
  23. *
  24. * <pre>
  25. * File dir = new File(".");
  26. * String[] files = dir.list( DirectoryFileFilter.INSTANCE );
  27. * for ( int i = 0; i < files.length; i++ ) {
  28. * System.out.println(files[i]);
  29. * }
  30. * </pre>
  31. *
  32. * @since Commons IO 1.0
  33. * @version $Revision: 1.7 $ $Date: 2004/02/23 04:37:57 $
  34. *
  35. * @author Henri Yandell
  36. * @author Stephen Colebourne
  37. * @author Peter Donald
  38. */
  39. public class DirectoryFileFilter extends AbstractFileFilter {
  40. /** Singleton instance of directory filter */
  41. public static final IOFileFilter INSTANCE = new DirectoryFileFilter();
  42. /**
  43. * Restrictive consructor.
  44. */
  45. protected DirectoryFileFilter() {
  46. }
  47. /**
  48. * Checks to see if the file is a directory.
  49. *
  50. * @param file the File to check
  51. * @return true if the file is a directory
  52. */
  53. public boolean accept(File file) {
  54. return file.isDirectory();
  55. }
  56. }