listDir method

  1. @override
Future<Result<List<FileInfo>, FileError>> listDir(
  1. String path
)
override

Lists the direct children of a directory.

Implementation

@override
Future<Result<List<FileInfo>, FileError>> listDir(String path) async {
  final resolved = _resolve(path);
  try {
    final infos = <FileInfo>[];
    await for (final entity in Directory(resolved).list(followLinks: false)) {
      final info = await fileInfo(entity.path);
      if (info.isOk) infos.add(info.valueOrNull!);
    }
    infos.sort((a, b) => a.name.compareTo(b.name));
    return Ok(infos);
  } on Object catch (error) {
    return Err(_toFileError(error, resolved));
  }
}