Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

dart

dart-io

I would like to list all the contents of a directory (on the file system) using Dart. How can I do this?

like image 448
Seth Ladd Avatar asked Jan 10 '13 23:01

Seth Ladd


People also ask

How do I list files in a directory in flutter?

To list all the files or folders, you have to use flutter_file_manager, path, and path_provider_ex flutter package. Add the following lines in your pubspec. yaml file to add this package in your dependency. Add read / write permissions in your android/app/src/main/AndroidManifest.

How do I get the current directory on DART?

Directory. current. path does it if you want a string, Directory. current for a Directory.

What is directory in DART?

A Directory is an object holding a path on which operations can be performed. The path to the directory can be absolute or relative. It allows access to the parent directory, since it is a FileSystemEntity.


1 Answers

The API has changed and I have updated the async code for M4 release (0.5.16_r23799 ):

Future<List<FileSystemEntity>> dirContents(Directory dir) {   var files = <FileSystemEntity>[];   var completer = Completer<List<FileSystemEntity>>();   var lister = dir.list(recursive: false);   lister.listen (        (file) => files.add(file),       // should also register onError       onDone:   () => completer.complete(files)       );   return completer.future; } 
like image 160
Nico Avatar answered Sep 24 '22 16:09

Nico