如何在lisp中迭代一个带参数的函数,而参数是文件名?

问题描述 投票:0回答:1

我有20个文本文件在一个文件夹里,我找不到任何解决方案,如何我的主函数,只有一个参数调用这些文件(文件的扩展名是 "txt")。我试过用通配符,但我得到的总是路径名。我的文件夹名是textfiles,其中包括20个文件,当我运行程序时,我也不能有任何参数。

lisp common-lisp
1个回答
0
投票

你可以试试下面的方法。

(defun my-func (dir)
    (setq pathname (make-pathname :name :wild :type "txt" :defaults (pathname dir)))
    (loop 
      for file in (directory pathname) do 
        (print (file-namestring file))))

如果你想打印一个文件的完整路径 你可以用namestring代替file -namestring.

© www.soinside.com 2019 - 2024. All rights reserved.