在 Clojure 中列出目录中的文件 [英] Listing files in a directory in Clojure

查看:14
本文介绍了在 Clojure 中列出目录中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从 Clojure 中特定目录中的所有文件中创建一个列表?我必须求助于调用 Java 还是 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?

推荐答案

使用 file-seq 函数.

Use file-seq function.

用法示例:

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

这篇关于在 Clojure 中列出目录中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆