scanTree method

Future<DirectoryTree<FileSystemEntity>> scanTree(
  1. String path, {
  2. TreeOptions options = const TreeOptions(),
})

Scans path with scan and builds a DirectoryTree from the entries.

With the default TreeOptions (minimal roots), the tree has a single top-level node, the scanned directory, because the scan includes it as a directory entry. Every node's data is the FileSystemEntity of its entry; no node is inferred.

Node paths are parsed by TreeOptions.paths, with the backslash rule below, from the paths dart:io reports. A relative path that the policy can represent, such as lib or ./src, is scanned as given, so the tree stays relative. A relative path that climbs above its start, such as .. or ../project, has no relative tree path, so this method scans Directory(path).absolute.path instead: the tree is then absolute, its .. segments resolved lexically by path parsing, and each node's data keeps the unresolved absolute spelling that dart:io reports (for example /home/me/work/../project/lib). scan and scanSync never make this substitution; they return paths exactly as dart:io reports them for the path given.

Backslashes follow the host: dart:io reports paths in host syntax, where \ separates segments on Windows but is an ordinary file-name character on Linux and macOS (w\z.txt is one file there). So this method always parses with PathPolicy.backslashIsSeparator set to Platform.isWindows, whatever options says, and keeps every other setting of options (including PathPolicy.caseSensitive and PathPolicy.unicodeNormalizer) as given. The returned tree's DirectoryTree.options show the policy actually used; it equals options only when options already followed the host rule.

Two more spellings follow the host on Linux and macOS, where a leading // means / and C: is an ordinary name, while path parsing reads them as a UNC root and a drive. There this method scans //x as /x, and a relative path whose first segment is a drive spec, such as C: or c:/x, as ./C: or ./c:/x, so the tree keeps a single top-level node and stays relative; the entries' paths use that spelling.

Completes with the same errors as scan.

Implementation

Future<DirectoryTree<FileSystemEntity>> scanTree(
  String path, {
  TreeOptions options = const TreeOptions(),
}) async {
  final effective = _hostOptions(options);
  return DirectoryTree<FileSystemEntity>.build(
    await scan(_treePath(path, effective)),
    options: effective,
  );
}