Search code examples
javaclojure

Listing files in a directory in Clojure


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?


Solution

  • Use file-seq function.

    Usage example:

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