recentFilesAndDirs method
- This function returns a
List
of int howMany
of type File of recently created files.
excludeHidded
if true
hidden files will not be returned
- sortedBy:
Sorting
- bool reversed: in case parameter sortedBy is used
Implementation
Future<List<File>> recentFilesAndDirs(int count,
{List<String>? extensions,
List<String>? excludedPaths,
excludeHidden: false,
FlutterFileUtilsSorting? sortedBy,
bool reversed: false}) async {
List<File> filesPaths = await filesTree(
excludedPaths: excludedPaths,
extensions: extensions,
excludeHidden: excludeHidden);
// note: in case that number of recent files are not sufficient, we limit the [howMany]
// to the number of the found ones
if (filesPaths.length < count) count = filesPaths.length;
var _sorted =
sortBy(filesPaths, FlutterFileUtilsSorting.Date, reversed: true);
// decrease length to howMany
_sorted = _sorted.getRange(0, count).toList();
if (sortedBy != null) {
return sortBy(filesPaths, sortedBy, reversed: reversed) as FutureOr<List<File>>;
}
return _sorted as FutureOr<List<File>>;
}