【问题标题】:How can I read all .text files in Lisp?如何阅读 Lisp 中的所有 .text 文件?
【发布时间】:2020-08-20 15:58:17
【问题描述】:

我想从 Lisp 的文件夹中读取所有文本文件?当我使用 shell 脚本时,就像 c 中的 "foldername/*.txt"。

【问题讨论】:

标签: lisp common-lisp readfile


【解决方案1】:
CL-USER 33 > (directory "/usr/share/examples/DTTk/*.txt")
(#P"/usr/share/examples/DTTk/hotspot_example.txt"
 #P"/usr/share/examples/DTTk/pridist_example.txt"
 #P"/usr/share/examples/DTTk/opensnoop_example.txt" 
 #P"/usr/share/examples/DTTk/syscallbysysc_example.txt"
 #P"/usr/share/examples/DTTk/rwbytype_example.txt"  ...)

CL-USER 34 > (mapcar (lambda (path)
                        (with-output-to-string (o)
                          (with-open-file (s path)
                            (loop for line = (read-line s nil)
                                  while line do (write-line line o)))))
                     *)
("The following is a demonstration of the hotspot.d script. ... " ...)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-05
    • 1970-01-01
    • 2021-07-02
    相关资源
    最近更新 更多