getFilesInPathByExt static method
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;
}