Listing files in a directory in Clojure

后端 未结 7 942
被撕碎了的回忆
被撕碎了的回忆 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条回答
  •  生来不讨喜
    2020-12-13 17:36

    (use 'clojure.java.io)
    (-> "/tmp" file .listFiles)
    

    The latter expression is an array of File-objects returned from the method listFiles, called on the file-object created from the path "/tmp". This is a fancy way to write:

    (.listFiles (file "/tmp"))
    

提交回复
热议问题