From: David Steuber
Subject: Testing for the existence of a file
Date: 
Message-ID: <87d619nrsj.fsf@david-steuber.com>
I want to test for the existence of a file named either foo.data or
foo.data.gz.  To do this, I created a wild pathname.  PROBE-FILE
doesn't like wild pathnames so I tried DIRECTORY instead.  DIRECTORY
worked for foo.data but failed for foo.data.gz.

The wild pathname was created like this:

(setq wild-file (make-pathname :name "foo" :type :wild))

The real pathname was created like so:

(setq file-name (make-pathname :name "foo" :type "data"))

And DIRECTORY was called thus:

(directory wild-file)

Is there a simple way to use a wild pathname to find both foo.data and
foo.data.gz?  Or do I have to construct a pathname for each?

-- 
An ideal world is left as an excercise to the reader.
   --- Paul Graham, On Lisp 8.1

From: Barry Margolin
Subject: Re: Testing for the existence of a file
Date: 
Message-ID: <barmar-B3BEDB.03261030082004@comcast.dca.giganews.com>
In article <··············@david-steuber.com>,
 David Steuber <·····@david-steuber.com> wrote:

> Is there a simple way to use a wild pathname to find both foo.data and
> foo.data.gz?  Or do I have to construct a pathname for each?

I don't think there's an easy way to match both at once without possibly 
matching other names.  foo.data is name "foo" and type "data", while 
foo.data.gz is name "foo.data" and type "gz".  You could try:

(directory "foo*.*")

but this will also match things like foobar.data.

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
From: Pascal Bourguignon
Subject: Re: Testing for the existence of a file
Date: 
Message-ID: <87eklool6g.fsf@thalassa.informatimago.com>
Barry Margolin <······@alum.mit.edu> writes:

> In article <··············@david-steuber.com>,
>  David Steuber <·····@david-steuber.com> wrote:
> 
> > Is there a simple way to use a wild pathname to find both foo.data and
> > foo.data.gz?  Or do I have to construct a pathname for each?
> 
> I don't think there's an easy way to match both at once without possibly 
> matching other names.  foo.data is name "foo" and type "data", while 
> foo.data.gz is name "foo.data" and type "gz".  You could try:
> 
> (directory "foo*.*")
> 
> but this will also match things like foobar.data.

That is to say, Common-Lisp CANNOT  access all the files and items in
your file system!  (ie. CANNOT reliably and portably).

To handle this dot problem, perhaps you should rename all the items to
match the "portability" rule of file systems:

  Use only one dot, preceded between one and eight  letters, digits,
  underline or dash, and followed between one and three  letters,
  digits, underline or dash.


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

Our enemies are innovative and resourceful, and so are we. They never
stop thinking about new ways to harm our country and our people, and
neither do we.
From: Vassil Nikolov
Subject: Re: Testing for the existence of a file
Date: 
Message-ID: <lzy8jwf10z.fsf@janus.vassil.nikolov.names>
Pascal Bourguignon <····@mouse-potato.com> writes:

> Barry Margolin <······@alum.mit.edu> writes:
>
>> In article <··············@david-steuber.com>,
>>  David Steuber <·····@david-steuber.com> wrote:
>> 
>> > Is there a simple way to use a wild pathname to find both foo.data and
>> > foo.data.gz?  Or do I have to construct a pathname for each?
>> 
>> I don't think there's an easy way to match both at once without possibly 
>> matching other names.  foo.data is name "foo" and type "data", while 
>> foo.data.gz is name "foo.data" and type "gz".  You could try:
>> 
>> (directory "foo*.*")
>> 
>> but this will also match things like foobar.data.
>
> That is to say, Common-Lisp CANNOT  access all the files and items in
> your file system!  (ie. CANNOT reliably and portably).
>
> To handle this dot problem, perhaps you should rename all the items to
> match the "portability" rule of file systems:
>
>   Use only one dot, preceded between one and eight  letters, digits,
>   underline or dash, and followed between one and three  letters,
>   digits, underline or dash.


  ...where each letter is one of the 26 uppercase letters of the
  English alphabet.  For even better portability, do not assume that
  the file name and the file type will always be separated by a dot in
  the pathnmame strings used by the operating system.

  ---Vassil.


-- 
Vassil Nikolov <········@poboxes.com>

Hollerith's Law of Docstrings: Everything can be summarized in 72 bytes.
From: Pascal Bourguignon
Subject: Re: Testing for the existence of a file
Date: 
Message-ID: <87acwcm0h1.fsf@thalassa.informatimago.com>
Vassil Nikolov <········@poboxes.com> writes:
> Pascal Bourguignon <····@mouse-potato.com> writes:
> > That is to say, Common-Lisp CANNOT  access all the files and items in
> > your file system!  (ie. CANNOT reliably and portably).
> >
> > To handle this dot problem, perhaps you should rename all the items to
> > match the "portability" rule of file systems:
> >
> >   Use only one dot, preceded between one and eight  letters, digits,
> >   underline or dash, and followed between one and three  letters,
> >   digits, underline or dash.
> 
> 
>   ...where each letter is one of the 26 uppercase letters of the
>   English alphabet.  For even better portability, do not assume that
>   the file name and the file type will always be separated by a dot in
>   the pathnmame strings used by the operating system.

But you can assume that the file name and the file type will always be
separated by a dot in Common-Lisp logical pathnames, since it's
specified so.

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

Our enemies are innovative and resourceful, and so are we. They never
stop thinking about new ways to harm our country and our people, and
neither do we.
From: Vassil Nikolov
Subject: Re: Testing for the existence of a file
Date: 
Message-ID: <lzisazfobm.fsf@janus.vassil.nikolov.names>
Pascal Bourguignon <····@mouse-potato.com> writes:

> Vassil Nikolov <········@poboxes.com> writes:
>> Pascal Bourguignon <····@mouse-potato.com> writes:
>> > That is to say, Common-Lisp CANNOT  access all the files and items in
>> > your file system!  (ie. CANNOT reliably and portably).
>> >
>> > To handle this dot problem, perhaps you should rename all the items to
>> > match the "portability" rule of file systems:
>> >
>> >   Use only one dot, preceded between one and eight  letters, digits,
>> >   underline or dash, and followed between one and three  letters,
>> >   digits, underline or dash.
>> 
>> 
>>   ...where each letter is one of the 26 uppercase letters of the
>>   English alphabet.  For even better portability, do not assume that
>>   the file name and the file type will always be separated by a dot in
>>   the pathnmame strings used by the operating system.
>
> But you can assume that the file name and the file type will always be
> separated by a dot in Common-Lisp logical pathnames, since it's
> specified so.


  I am tempted to call logical pathnames that are constrained by the
  eight- and three-character limits, and that can have underscores,
  physiological pathnames. From there it's not a big step to also
  introduce the notion of anatomical pathnames...

  ---Vassil.


-- 
Vassil Nikolov <········@poboxes.com>

Hollerith's Law of Docstrings: Everything can be summarized in 72 bytes.
From: Thomas A. Russ
Subject: Re: Testing for the existence of a file
Date: 
Message-ID: <ymillfwcsum.fsf@sevak.isi.edu>
David Steuber <·····@david-steuber.com> writes:

> 
> I want to test for the existence of a file named either foo.data or
> foo.data.gz.  To do this, I created a wild pathname.  PROBE-FILE
> doesn't like wild pathnames so I tried DIRECTORY instead.  DIRECTORY
> worked for foo.data but failed for foo.data.gz.
> 
> The wild pathname was created like this:
> 
> (setq wild-file (make-pathname :name "foo" :type :wild))
> 
> The real pathname was created like so:
> 
> (setq file-name (make-pathname :name "foo" :type "data"))
> 
> And DIRECTORY was called thus:
> 
> (directory wild-file)
> 
> Is there a simple way to use a wild pathname to find both foo.data and
> foo.data.gz?  Or do I have to construct a pathname for each?

Some of this is really just related to parsing issues and determining
what is the name and what is the type of the file.  Most of the Unix
implementations that I am aware of set the type of the file to be the
last "."-separated component.

Using the pathname notation, this means that the two files would have to
be specified as

   (make-pathname :name "foo" :type "data")
   (make-pathname :name "foo.data" :type "gz")

which makes it clear why a wildcard solely on the file type will not
find both files.

It looks like you will have to construct a pathname for each.  On the
other hand, it also means you can use PROBE-FILE as your function and
with a bit of encapsulation, it isn't even all that bad a function:

(defun find-possibly-compressed-file (name type &optional (compression-suffix "gz"))
  (or (probe-file (make-pathname :name name
                                 :type type))
      (probe-file (make-pathname :name (concatenate 'string name "." type)
                                 :type compression-suffix))))


-- 
Thomas A. Russ,  USC/Information Sciences Institute
From: Wade Humeniuk
Subject: Re: Testing for the existence of a file
Date: 
Message-ID: <CsKYc.56071$S55.42141@clgrps12>
David Steuber wrote:


> Is there a simple way to use a wild pathname to find both foo.data and
> foo.data.gz?  Or do I have to construct a pathname for each?
> 

Just do something like

(remove nil (list (probe-file "foo.data")
	          (probe-file "foo.data.gz")))

if you want both, 1 or none...

or...

(or (probe-file "foo.data")
     (probe-file "foo.data.gz"))

foo.data if it exists, foo.data.gz if it exists
and foo.data does not, or nil if neither exists.

Wade