listFiles function

List<String?> listFiles(
  1. String path, [
  2. bool recursive = false,
  3. bool allFiles = false
])

Implementation

List<String?> listFiles(String path,
    [bool recursive = false, bool allFiles = false]) {
  final files = <String?>[];
  try {
    var dir = Directory(path);

    final dartFile = allFiles ? Glob('**') : Glob('**.dart');

    List contents = dir.listSync(recursive: recursive);

    for (var fileOrDir in contents) {
      if (dartFile.matches(fileOrDir.path)) {
        files.add(fileOrDir.path);
      }
    }
  } catch (e) {
    print('Exception while listing files: $e');
  }
  files.sort();
  return files;
}