How to check if FileSystemEntity is a Directory

29 Views Asked by At

Problem

I get the FileSystemEntity list and want to select only Directories from it. So I create a new list and remove all entity types from it except Directory. However, the list just happens to be empty (it is guaranteed that subdirectories exist).

final inputDir = Directory(path); // home

final onlyDirs = await inputDir.list().toList(); // get subdirs
onlyDirs.removeWhere((element) => element.runtimeType != Directory); // remove all except Directory

My solution

I was trying to check element.runtimeType is! Directory, but it does not work at all. Debugger says that element.runtimeType is _Directory, but obviously I can't use private class in my comparator.

Question

How to remove all entities except directories from the List<FileSystemEntity>?

0

There are 0 best solutions below