ls method
List all files in current (or specified) directory.
Maps to: ls
Returns list of names (directories end with /).
Implementation
@override
List<String> ls([String? path]) {
final targetPath = path != null ? _state.resolvePath(path) : _state.cwd;
final dir = Directory(targetPath);
if (!dir.existsSync()) {
throw DirectoryNotFoundException(targetPath);
}
final entries = dir.listSync();
final result = <String>[];
for (final entry in entries) {
// Use path.split to get the name since uri.pathSegments.last
// returns empty string for directories
final segments = entry.path.split('/');
final name = segments.last.isEmpty && segments.length > 1
? segments[segments.length - 2]
: segments.last;
if (entry is Directory) {
result.add('$name/');
} else {
result.add(name);
}
}
return result..sort();
}