且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何遍历Common Lisp中的目录?

更新时间:2023-11-28 18:21:16

您的路径名规范是否包含通配符?起初,Common Lisp的路径名东西有些难以理解-至少对我来说是...... CLHS 目录函数上的状态:

Does your pathname specification contain a wildcard? Common Lisp's pathname stuff is somewhat hard to grasp at first - at least for me it was... As the CLHS states on the directory function:


如果pathspec不为空,则
结果列表将包含
零或一个元素。

If the pathspec is not wild, the resulting list will contain either zero or one elements.

要让您的路径名包含通配符,您可以尝试使用make-pathname函数,例如

In order to have your pathname include a wildcard, you might try the make-pathname function, like

(directory (make-pathname :directory '(:absolute "srv" "hunchentoot") :name :wild :type "lisp"))

甚至

(directory (make-pathname :directory '(:absolute "srv" "hunchentoot") :name :wild :type :wild))

我发现 CL-FAD 库对于处理路径名和文件系统有很大的帮助米特别是其 列表目录 函数可能比普通的标准目录函数更易于使用。

I found the CL-FAD library a great help for dealing with pathnames and the file system. In particular, its list-directory function might be easier to use than the plain standard directory function.