By Alvin Alexander. Last updated: June 6, 2016
Here's a snippet of Scala code I use to get a list of all files beneath a given directory:
/** * Get a recursive listing of all files underneath the given directory. * from stackoverflow.com/questions/2637643/how-do-i-list-all-files-in-a-subdirectory-in-scala */ def getRecursiveListOfFiles(dir: File): Array[File] = { val these = dir.listFiles these ++ these.filter(_.isDirectory).flatMap(getRecursiveListOfFiles) }
I use this code in my FileUtils
class in my Blue Parrot app. The full source of the FileUtils
class is at https://github.com/alvinj/BlueParrot/blob/master/src/main/scala/com/alvinalexander/blueparrot/FileUtils.scala.