getFilesInPathByExt static method

List<String> getFilesInPathByExt(
  1. String parentPath, [
  2. String? ext
])

Get the list of files names from a given parentPath and optionally filtered by ext.

Implementation

static List<String> getFilesInPathByExt(String parentPath, [String? ext]) {
  List<String> filenameList = [];

  try {
    Directory(parentPath).listSync().forEach((FileSystemEntity fse) {
      String path = fse.path;
      String filename = basename(path);
      if (ext == null || filename.endsWith(ext)) {
        filenameList.add(filename);
      }
    });
  } catch (e) {
    print(e);
  }
  return filenameList;
}