Listing files in a directory in Clojure

后端 未结 7 945
被撕碎了的回忆
被撕碎了的回忆 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:38

    To make the modified code match the functionality of original sample code you should add the call to get the file names, like this.

    (def directory (clojure.java.io/file "/path/to/directory"))
    (def files 
        (for [file (file-seq directory)] (.getName file)))
    (take 10 files)
    

提交回复
热议问题