Skip to content

Instantly share code, notes, and snippets.

@elarib
Created March 20, 2019 16:14
Show Gist options
  • Save elarib/8bedc6ab18067e39c9dd9bbcd23be873 to your computer and use it in GitHub Desktop.
Save elarib/8bedc6ab18067e39c9dd9bbcd23be873 to your computer and use it in GitHub Desktop.
List recusively directories
def listSubdirectoriesRecursively(
directory: Path,
list: mutable.ListBuffer[Path] = new mutable.ListBuffer[Path]
): List[Path] = {
val iterator = fs.listLocatedStatus(directory)
while (iterator.hasNext) {
val pathStatus = iterator.next()
val path = pathStatus.getPath
if (pathStatus.isDirectory)
if (fs.getContentSummary(path).getDirectoryCount == 1)
list += path
else listSubdirectoriesRecursively(path, list)
}
list.sortBy(_.toString).toList
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment