From: Marc Battyani
Subject: merge-pathnames
Date: 
Message-ID: <737B74DD4D071E29.D60B1639977647AC.3B4DD50B8AC6ED32@lp.airnews.net>
I have a function that receive a pathname representing a directory but the
name and type are set to :unspecific so when I use #'directory on this
pathname it returns the pathname.
It's ok so far but is there a better way than transforming the pathname to a
namestring and merge it with "*.*" to get #'directory to give me the files
in tht directory?

(directory (merge-pathnames "*.*" (namestring dir)))

Thanks

Marc Battyani

From: Kent M Pitman
Subject: Re: merge-pathnames
Date: 
Message-ID: <sfwn1ug3or9.fsf@world.std.com>
"Marc Battyani" <·············@csi.com> writes:

> I have a function that receive a pathname representing a directory but the
> name and type are set to :unspecific so when I use #'directory on this
> pathname it returns the pathname.
> It's ok so far but is there a better way than transforming the pathname to a
> namestring and merge it with "*.*" to get #'directory to give me the files
> in tht directory?
> 
> (directory (merge-pathnames "*.*" (namestring dir)))


This is not reliable.  In fact, I'm not sure there is anything that is
reliable.  Vendors vary as to whether they will do the right thing with
these things because there is no agreement on the namestring representation
of directories nor of whether directoryness is allowed to take into 
account the question of whether the corresponding file on disk is
a directory.  Personaly, I find it abhorrent that the pathname operations
would probe the file system to find out a matter of what syntax should
merge in what way.  and since

 (merge-pathname "x" "/foo")

becomes "/x" if foo is not a directory and "/foo/x" if foo is a directory
in some implementations, that's a problem for me.  My solution is generally
to write functions that find the directory pathname and manually check it to
see if it has a non-null name component and do the appropriate call to
APPEND to attach it to the directory and then manually do the merge.
I bundle this up into functions that are called things like
directory-as-pathname and pathname-as-directory, for example.  And then
I do 
  (directory  (merge-pathnames "*.*" (directory-as-pathname dir)))
It's an extremely messy business and it's worth checking each implementation
you're going to run in to find out what its rules are and whether there is
already a utility which does exactly this thing.

It's something we should really fix in ANSI CL, though we've not yet
decided what our charter will be for the upcoming round of restandardization.

Anyway, if you're having troubles it's because it's a gray area in the
original specification, not because you're misunderstanding something.

Oh, and by the way, although potentially :unspecific can be used in any
slot, implementations are not required to allow :unspecific in all the slots
so I don't think that's portable.  I usually put NIL's in the slots of a
directory rather than :unspecific, even though it's more fragile.
From: Erik Naggum
Subject: Re: merge-pathnames
Date: 
Message-ID: <3146888016725543@naggum.no>
* "Marc Battyani" <·············@csi.com>
| I have a function that receive a pathname representing a directory but
| the name and type are set to :unspecific so when I use #'directory on
| this pathname it returns the pathname.

  I'm not sure what it should return in that case, but such a pathname
  argument is not a physically existing pathname.  I'd expect () as the
  return value.

| It's ok so far but is there a better way than transforming the pathname
| to a namestring and merge it with "*.*" to get #'directory to give me the
| files in tht directory?

(make-pathname :name :wild :type :wild :defaults <whatever>)

#:Erik