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

后端 未结 19 1490
旧巷少年郎
旧巷少年郎 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条回答
  •  再見小時候
    2020-11-28 03:56

    It seems nobody mentions the scala-io library from scala-incubrator...

    import scalax.file.Path
    
    Path.fromString("c:\temp") ** "a*.foo"
    

    Or with implicit

    import scalax.file.ImplicitConversions.string2path
    
    "c:\temp" ** "a*.foo"
    

    Or if you want implicit explicitly...

    import scalax.file.Path
    import scalax.file.ImplicitConversions.string2path
    
    val dir: Path = "c:\temp"
    dir ** "a*.foo"
    

    Documentation is available here: http://jesseeichar.github.io/scala-io-doc/0.4.3/index.html#!/file/glob_based_path_sets

提交回复
热议问题