scanSync method
Lists the directory at path and everything below it synchronously.
Returns the same entries as scan (see DirectoryScanner for their shape and order), but blocks the isolate until the whole walk is done, so prefer scan in servers, UIs, and other code that must stay responsive.
Throws a PathNotFoundException when nothing exists at path
(including a broken link), a FileSystemException when path exists
but is not a directory (or a link to one), and an ArgumentError when
maxDepth is negative. Failures below the root go to onError
instead.
The paths use host syntax; to build a tree from them, parse them with
PathPolicy(backslashIsSeparator: Platform.isWindows, ...) (see
DirectoryScanner), or call scanTree, which does.
Takes O(n log n) time for n reported entities, plus one directory listing per listed directory.
Implementation
List<TreeEntry<FileSystemEntity>> scanSync(String path) {
_checkMaxDepth();
final root = _root(path);
final walk = _Walk(
this,
root,
rootResolved: followLinks ? _resolveRootSync(root) : null,
);
while (walk.isNotDone) {
final visit = walk.next();
if (visit == null) continue;
final List<FileSystemEntity> children;
try {
children = _listSync(visit.directory);
} on FileSystemException catch (error) {
onError?.call(error);
continue;
}
for (final child in children) {
if (walk.isHidden(child)) continue;
if (child is Link && followLinks) {
walk.addLink(child, visit, _followSync(child));
} else {
walk.add(child, visit);
}
}
}
return walk.sortedEntries();
}