boolean (@NotNull VirtualFile file) { if (file.getParent() == null) { return true; // assume roots always have children } try (DirectoryStream<Path> stream = Files.newDirectoryStream(Paths.get(file.getPath()))) { return stream.iterator().hasNext(); // make sure to not load all children } catch (DirectoryIteratorException e) { return false; // a directory can't be iterated over } catch (InvalidPathException | IOException | SecurityException e) { return true; } }