How do I list the contents of a directory with Dart? - Stack Overflow

PHOTO EMBED

Fri Jun 17 2022 08:07:23 GMT+0000 (Coordinated Universal Time)

Saved by @X17

// How to list the contents of a directory in Dart
final dir = Directory('path/to/directory');
final List<FileSystemEntity> entities = await dir.list().toList();

//This creates a Directory from a path. Then it converts it to a list of FileSystemEntity, which can be a File, a Directory, or a Link. By default subdirectories are not listed recursively.

//If you want to print that list, then add this line:

entities.forEach(print);

//If you want to only get the files then you could do it like so:

final Iterable<File> files = entities.whereType<File>();
content_copyCOPY

https://stackoverflow.com/questions/14268967/how-do-i-list-the-contents-of-a-directory-with-dart