Skip to content

Instantly share code, notes, and snippets.

@aembleton
Created September 19, 2013 09:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aembleton/6621168 to your computer and use it in GitHub Desktop.
Save aembleton/6621168 to your computer and use it in GitHub Desktop.
Gets a list of files in a given directory and all child directories
/**
* Gets a list of files in a given directory and all child directories
* @param f This is the File representing the root directory
* @return A list of File objects, each one representing a File inside f, either directly or in a sub-directory
*/
def listFiles(f: File): List[File] = f match{
case f if f.isDirectory => f.listFiles.toList.flatMap(listFiles(_))
case f if f.isFile => List(f)
case _ => Nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment