Package manifold.io

Class FileTreeWalk

  • All Implemented Interfaces:
    Iterable<File>

    public class FileTreeWalk
    extends Object
    implements Iterable<File>
    This class is intended to implement different file traversal methods. It allows to iterate through all files inside a given directory.

    Use File.walk, File.walkTopDown or File.walkBottomUp extension methods to instantiate a FileTreeWalk instance.

    If the file path given is just a file, walker iterates only it. If the file path given does not exist, walker iterates nothing, i.e., it's equivalent to an empty sequence.

    • Method Detail

      • onEnter

        public FileTreeWalk onEnter​(Function<File,​Boolean> function)
        Sets a predicate [function], that is called on any entered directory before its files are visited and before it is visited itself.

        If the [function] returns `false` the directory is not entered and neither it nor its files are visited.

      • onLeave

        public FileTreeWalk onLeave​(Consumer<File> function)
        Sets a callback [function], that is called on any left directory after its files are visited and after it is visited itself.
      • onFail

        public FileTreeWalk onFail​(BiConsumer<File,​IOException> function)
        Set a callback [function], that is called on a directory when it's impossible to get its file list.

        [onEnter] and [onLeave] callback functions are called even in this case.

      • maxDepth

        public FileTreeWalk maxDepth​(int depth)
        Sets the maximum [depth] of a directory tree to traverse. By default there is no limit.

        The value must be positive and [Int.MAX_VALUE] is used to specify an unlimited depth.

        With a value of 1, walker visits only the origin directory and all its immediate children, with a value of 2 also grandchildren, etc.