5

The characters * and ? are used as wildcards in pathnames. How does one refer to a filename that has ? as one of its actual characters? For example: [18]> (wild-pathname-p #p"foo") NIL [19]> (wild-pathname-p #p"foo?") T So referring to the filename "foo?" cannot be done this way. I tried to escape the ? with a backslash, but that didn't work. I tried going unicode by using \u3f or \u003f, but that didn't work.

How do I refer to a file that contains a wildcard as part of its name: How to probe it, open it, etc.?

Rainer Joswig
  • 136,269
  • 10
  • 221
  • 346
Mayer Goldberg
  • 1,378
  • 11
  • 23

3 Answers3

3

It depends on the implementation, but for some, a backslash does in fact work. But because namestrings are strings, to get a string with a backslash in it, you have to escape the backslash with another backslash. So, for example, "foo?" is escaped as "foo\\?", not "foo\?".

Last time I checked, in CLISP, there is no way to refer to files with wildcards in the names. My solution to that is to avoid CLISP.

Xach
  • 11,774
  • 37
  • 38
  • 1
    SBCL exhibits similar behaviour as CLISP, so apparently the common lisp standard doesn't include a mechanism for escaping the wildcard, which is weird. What is no less weird is that cltl2, page 628 gives a BNF for pathname namestrings, and this does not include the `?` character. Only `*` ad `**` – Mayer Goldberg May 05 '15 at 20:49
  • SBCL supports escaping with backslashes. – Xach May 05 '15 at 20:50
  • 1
    Unix-style globbing with `*` and `?` within pathname components is a non-standard but frequent extension to pathnames and namestring syntax. – Xach May 05 '15 at 20:51
  • 1
    Do you mean something like: `* (wild-pathname-p #p"foo?") T * (wild-pathname-p #p"foo\?") T * (wild-pathname-p #p"foo\\?") NIL` – Mayer Goldberg May 05 '15 at 20:52
  • 2
    You can refer to a file with a Unix pathname of "foo?" with #p"foo\\?" in SBCL. – Xach May 05 '15 at 20:56
1

On my Mac running Mac OS X 10.10.3: Clozure CL, SBCL and LispWorks write a pathname with * like this:

#P"/private/tmp/test.\\*"

They might differ in some other details, though.

Rainer Joswig
  • 136,269
  • 10
  • 221
  • 346
  • (wild-pathname-p #p"test.\\*") returns T in sbcl but NIL in clisp. This seems to be the issue: There is no way of removing the special status of the wildcards in clisp. – Mayer Goldberg May 07 '15 at 17:47
0

SBCL supports (make-pathname :directory "" :name file) to escape a string to a proper pathname.

HappyFace
  • 3,439
  • 2
  • 24
  • 43