Home > Enterprise >  How to read the files in a folder recursively an asynchronously
How to read the files in a folder recursively an asynchronously

Time:11-25

How can I read a folder contents (recursively) without blocking the main thread?

I have checked the Directory class and has 2 methods:

  1. listSync to read the folder in a synchronous fashion
  2. list to read the folder asynchronously but I don' really know when it finishes listing. This seems like a way to hear to folder content changes?

They both doesn't seem to be what I need.

Are isolates the only option left to read the files in a folder async?

CodePudding user response:

simply use toList() method:

final directory = Directory('downloads');
final elements = directory.list(recursive: true).toList();
print(await elements);
  • Related