View source code
Display the source code in std/file.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

Enum std.file.SpanMode

Dictates directory spanning policy for dirEntries (see below).

enum SpanMode : int { ... }

Enum members

NameDescription
breadth Spans the directory in depth-first pre-order, i.e. the content of any subdirectory is spanned right after that subdirectory itself.

Note that SpanMode.breadth will not result in all directory members occurring before any subdirectory members, i.e. it is not true breadth-first traversal.

depth Spans the directory in depth-first post-order, i.e. the content of any subdirectory is spanned before that subdirectory itself. Useful e.g. when recursively deleting files.
shallow Only spans one directory.

Example

import std.algorithm.comparison : equal;
import std.algorithm.iteration : map;
import std.algorithm.sorting : sort;
import std.array : array;
import std.path : buildPath, relativePath;

auto root = deleteme ~ "root";
scope(exit) root.rmdirRecurse;
root.mkdir;

root.buildPath("animals").mkdir;
root.buildPath("animals", "cat").mkdir;

alias removeRoot = (return scope e) => e.relativePath(root);

assert(root.dirEntries(SpanMode.depth).map!removeRoot.equal(
    [buildPath("animals", "cat"), "animals"]));

assert(root.dirEntries(SpanMode.breadth).map!removeRoot.equal(
    ["animals", buildPath("animals", "cat")]));

root.buildPath("plants").mkdir;

assert(root.dirEntries(SpanMode.shallow).array.sort.map!removeRoot.equal(
    ["animals", "plants"]));

Authors

Walter Bright, Andrei Alexandrescu, Jonathan M Davis

License

Boost License 1.0.