How do I list all files in a subdirectory in scala?

后端 未结 19 1521
旧巷少年郎
旧巷少年郎 2020-11-28 03:35

Is there a good \"scala-esque\" (I guess I mean functional) way of recursively listing files in a directory? What about matching a particular pattern?

For example re

19条回答
  •  旧时难觅i
    2020-11-28 04:13

    How about

       def allFiles(path:File):List[File]=
       {    
           val parts=path.listFiles.toList.partition(_.isDirectory)
           parts._2 ::: parts._1.flatMap(allFiles)         
       }
    

提交回复
热议问题