The way to traverse directories. See docs
do we need to follow symlinks of not. By default set to True.
// Iterate over paths in current directory foreach (p; Path.current.walk(SpanMode.breadth)) { if (p.isFile) writeln(p);
import dshould; Path root = createTempPath(); scope(exit) root.remove(); // Create sample directory structure root.join("d1", "d2").mkdir(true); root.join("d1", "test1.txt").writeFile("Test 1"); root.join("d1", "d2", "test2.txt").writeFile("Test 2"); // Walk through the derectory d1 Path[] result; foreach(p; root.join("d1").walk(SpanMode.breadth)) { result ~= p; } import std.algorithm: sort; import std.array: array; result.sort.array.should.equal([ root.join("d1", "d2"), root.join("d1", "d2", "test2.txt"), root.join("d1", "test1.txt"), ]);
Walk inside tilda-expandable path
import dshould; import std.algorithm: startsWith; // Prepare test dir in user's home directory Path root = createTempPath("~", "tmp-d-test"); scope(exit) root.remove(); Path hroot = Path("~").join(root.relativeTo(std.path.expandTilde("~"))); hroot._path.startsWith("~").should.be(true); // Create sample directory structure hroot.join("d1", "d2").mkdir(true); hroot.join("d1", "test1.txt").writeFile("Test 1"); hroot.join("d1", "d2", "test2.txt").writeFile("Test 2"); // Walk through the derectory d1 Path[] result; foreach(p; hroot.join("d1").walk(SpanMode.breadth)) { result ~= p; } import std.algorithm: sort; import std.array: array; result.sort.array.should.equal([ root.join("d1", "d2"), root.join("d1", "d2", "test2.txt"), root.join("d1", "test1.txt"), ]);
Iterate over all files and directories inside path;
Produces rangs with absolute paths found inside specific directory