Listing files in a directory in Clojure

后端 未结 7 933
被撕碎了的回忆
被撕碎了的回忆 2020-12-13 17:14

How can I create a list out of all of the files in a specific directory in Clojure? Do I have to resort to calling Java or can Clojure handle this natively?

7条回答
  •  萌比男神i
    2020-12-13 17:27

    Usually, when we say that we want to list directory, we mean that we want to get file names or paths, so ->

    Simplest way to list directory:

    (seq (.list (clojure.java.io/file ".")))
    

    If you want to list it recursive, then:

    (map #(.getPath %)
         (file-seq (clojure.java.io/file ".")))
    

提交回复
热议问题