Path.walk

auto walk(bool topDown = true, bool followSymlinks = false, bool delegate(const Path) dirFilter = null) const

Recursively traverses the directory tree rooted at this and yields WalkEntry values describing each directory and its immediate children.

Semantics are inspired by Python's os.walk and pathlib.Path.walk:

  • Traversal order can be top-down (pre-order, default) or bottom-up (post-order) controlled by topDown.
  • Symlink traversal is disabled by default; when followSymlinks is true, symlinked directories may be traversed, with loop protection to avoid cycles. To keep results predictable, traversal suppresses revisiting the same physical directory (device+inode on POSIX; absolute resolved path on Windows), which prevents duplicates when the same directory is reachable via multiple paths.
  • Pruning: if dirFilter is provided, any subdirectory for which dirFilter(childDirPath) returns false is excluded from the yielded dirs list and is not traversed.
  • Error handling: errors while listing a directory are ignored for that subtree (it is skipped), and iteration continues. This provides robust behavior similar to typical walkers.
  • Non-directory roots: If this is not a directory, the returned range is empty.

    Parameters

    topDownIf true, yield parent directories before their children; if false, yield after traversing children.
    followSymlinksWhether to traverse into symlinked directories.
    dirFilterOptional pruning predicate. When provided and it returns false for a child directory, that child is omitted and not descended into.

    Examples

    // Pre-order walk (top-down) with simple pruning
    bool delegate(const Path) prune = (const Path p) => p.name() != ".git";
    foreach (step; Path("/project").walk(true, false, prune)) {
        // step.root, step.dirs, step.files
    }

    Returns

    A lazy input range of WalkEntry values.