Как я могу прочитать все текстовые файлы в Лиспе? - PullRequest
0 голосов
/ 05 мая 2020

Я хочу прочитать все текстовые файлы из папки в Lisp? Как "имя папки / *. Txt" в c, когда я использую сценарий оболочки.

1 Ответ

6 голосов
/ 05 мая 2020
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. ... " ...)
...