children_ method
Lists all the FileSystemEntitys present in the Directory.
- Safely handles long file-paths on Windows: https://github.com/dart-lang/sdk/issues/27825
- Does not terminate on errors e.g. an encounter of
Access Is Denied
. - Does not follow links.
Implementation
Future<List<FileSystemEntity>> children_() async {
final completer = Completer();
final contents = <FileSystemEntity>[];
try {
Directory(addPrefix(path))
.list(recursive: false, followLinks: false)
.listen(
(event) {
switch (FS.typeSync_(event.path)) {
case FileSystemEntityType.directory:
contents.add(Directory(removePrefix(event.path)));
break;
case FileSystemEntityType.file:
contents.add(File(removePrefix(event.path)));
break;
default:
break;
}
},
onError: (error) {
// For debugging. In case any future error is reported by the users.
print(error.toString());
},
onDone: completer.complete,
);
await completer.future;
return contents;
} catch (exception, stacktrace) {
print(exception.toString());
print(stacktrace.toString());
return [];
}
}