listFolders function

Future<List<String>> listFolders(
  1. Directory path, {
  2. List<String>? excludedFolders,
  3. List<String>? excludedPaths,
  4. bool excludeHidden = false,
  5. dynamic followLinks = false,
  6. FlutterFileUtilsSorting? sortedBy,
  7. bool reversed = false,
})

This function return list of folders of type String , not full paths Directory.

e.g: listFolders(Directory("/")) = root, usr, var, proc, mnt ...

  • hidden: this parameter excludes folders starts with " . "
  • excludedFolders: this parameter excludes folders from the result
  • sortedBy: Sorting
  • bool reversed: in case parameter sortedBy is used
  • examples: "Android", "Download", "DCIM", ....

Implementation

Future<List<String>> listFolders(Directory path,
    {List<String>? excludedFolders,
    List<String>? excludedPaths,
    bool excludeHidden: false,
    followLinks: false,
    FlutterFileUtilsSorting? sortedBy,
    bool reversed: false}) async {
  List<String> folders = (await listDirectories(path,
          excludeHidden: excludeHidden,
          followLinks: false,
          reversed: reversed,
          sortedBy: sortedBy))
      .map((Directory directory) => pathlib.split(directory.absolute.path).last)
      .toList();
  return folders;
}