0

I'm new to this dart stuff and having problems with creating a list with file names from a directory. The example code makes sense but doesn't work and provides no error messages.

I'm really not enjoying how Dart complicates simple tasks.

var flist = new List();
Process.run('cmd', ['/c', 'dir *.txt /b']).then((ProcessResult results) {
 flist.add(results.toString());
});

i know it's way off.. how do i go about this without having to call any outside voids.. i'd like to keep my code in the 'main' function.

Biagio Chirico
  • 646
  • 5
  • 14
ace007
  • 577
  • 1
  • 10
  • 20

1 Answers1

2

You might find this answer useful. It shows how to use the Directory object to list contents of a directory: How do I list the contents of a directory with Dart?

Looks like you're trying to find all files in a directory that end in *.txt. You could do this:

import 'dart:io';

main() {
  var dir = new Directory('some directory');
  var contents = dir.listSync();
  var textFiles = contents.filter((f) => f.name.endsWith('.txt'));
}
Community
  • 1
  • 1
Seth Ladd
  • 112,095
  • 66
  • 196
  • 279