4
votes

SBCL (directory "*") is filtering out some file names based on extension. How do I get it to return all files, or especially all files matching a pattern (as in bash globing)

(directory "*") ;Lists some files, not all (directory "MyFile") ;Lists some files, but again, filters by extension

Extensions that seem to me ignored... at least *.lisp is not listed.

SBCL 1.1.2-1.fc18 on Fedora18

3
Here's a good deal of examples + explanation. But, bottom line, and it is also important, that this behavior is implementation-defined. So, while most implementations will do the same thing, there may be variations. When working with Unix pathnames I'd certainly want to start with either dot or slash to make sure it is interpreted the way I intend. So, I'd start off with either ./* or /* and would work from there. - user797257

3 Answers

5
votes

May be you should use native form:

(directory (make-pathname :name :wild :type :wild))

As all this strange signs *?.* don't increase understandability of the code. Lisp is not supposed to be one-liners language. :)

But if you want just list all files in the directory, you may use cl-fad function list-directory.

4
votes

The translation from globs to pathnames is implementation and system dependent. Pathnames distinguish the filename and the filetype (extension). When you specify just *, SBCL on Linux interprets this as "any filename, but extension must be empty". You can say *.* to specify all files. The . in *.* is interpreted as the separation between filename and extension, so *.* means not just the filenames containing a literal dot.

2
votes

Lisp uses paths and they call *.XXX the type of the file. (directory "*") is filtering some "types" (I still don't understand it all), but freenode.net IRC user pjb points out

(concatenate 'list (directory "*.*") (directory "*")  (directory "*/"))

and that does better. (Still not perfect, but passable and pointing in the right direction.)