From: danb
Subject: <pathname-directory>/sub/dir
Date: 
Message-ID: <da02bce5-306e-4762-ba4c-966e7fa2939f@x35g2000hsb.googlegroups.com>
How do you create a subdirectory of another pathname
directory?  Is that something that some filesystems don't
understand?  It looks like there's at least one posix/unix
format that's a list, where you can append the subdirectory
names to the existing directory list, but how reliable or
universal is that, and where is the format defined?  I've
only seen an example in the HS.

--Dan

------------------------------------------------
Dan Bensen  http://www.prairienet.org/~dsb/

cl-match:  expressive pattern matching in Lisp
http://common-lisp.net/project/cl-match/

From: Zach Beane
Subject: Re: <pathname-directory>/sub/dir
Date: 
Message-ID: <m3od713ycp.fsf@unnamed.xach.com>
danb <·········@gmail.com> writes:

> How do you create a subdirectory of another pathname
> directory?  Is that something that some filesystems don't
> understand?  It looks like there's at least one posix/unix
> format that's a list, where you can append the subdirectory
> names to the existing directory list, but how reliable or
> universal is that, and where is the format defined?  I've
> only seen an example in the HS.

I often use something like this:

  (merge-pathnames #p"sub/dir/" existing-pathname)

Or:

  (merge-pathnames (make-pathname :directory '(:relative "sub" "dir"))
                   existing-pathname)

Zach
From: danb
Subject: Re: <pathname-directory>/sub/dir
Date: 
Message-ID: <12ba739f-3d4a-43e6-a654-9c469f77e01a@m36g2000hse.googlegroups.com>
> danb <·········@gmail.com> writes:
> > How do you create a subdirectory of another pathname
> > directory?

On May 20, 8:21 am, Zach Beane <····@xach.com> wrote:
>   (merge-pathnames #p"sub/dir/" existing-pathname)
>   (merge-pathnames (make-pathname :directory '(:relative "sub" "dir"))
>                    existing-pathname)

Thanks, Zach.  How portable is that, and are the
directory and namestring formats documented somewhere?

--Dan

------------------------------------------------
Dan Bensen  http://www.prairienet.org/~dsb/

cl-match:  expressive pattern matching in Lisp
http://common-lisp.net/project/cl-match/
From: Marco Antoniotti
Subject: Re: <pathname-directory>/sub/dir
Date: 
Message-ID: <2ed71d55-d98c-40f0-8b85-6cb1aa88d057@c58g2000hsc.googlegroups.com>
On May 20, 4:12 pm, danb <·········@gmail.com> wrote:
> > danb <·········@gmail.com> writes:
> > > How do you create a subdirectory of another pathname
> > > directory?
>
> On May 20, 8:21 am, Zach Beane <····@xach.com> wrote:
>
> >   (merge-pathnames #p"sub/dir/" existing-pathname)
> >   (merge-pathnames (make-pathname :directory '(:relative "sub" "dir"))
> >                    existing-pathname)
>
> Thanks, Zach.  How portable is that,

The second is mostly portable (subtle issue always creep in with
pathnames), the first one probably with UN*X-like file systems (but
mostly implementation dependent).

> and are the
> directory and namestring formats documented somewhere?

No (not in the ANSI spec) and yes (partially in
http://common-lisp.net/project/names-and-paths/ : usual shameless
plug).

Cheers
--
Marco
From: Thomas A. Russ
Subject: Re: <pathname-directory>/sub/dir
Date: 
Message-ID: <ymir6bwc3pp.fsf@blackcat.isi.edu>
danb <·········@gmail.com> writes:

> > danb <·········@gmail.com> writes:
> > > How do you create a subdirectory of another pathname
> > > directory?
> 
> On May 20, 8:21 am, Zach Beane <····@xach.com> wrote:
> >   (merge-pathnames #p"sub/dir/" existing-pathname)
> >   (merge-pathnames (make-pathname :directory '(:relative "sub" "dir"))
> >                    existing-pathname)
> 
> Thanks, Zach.  How portable is that, and are the
> directory and namestring formats documented somewhere?

The second form should be highly portable, at least to lisp
implementations running on machines with hierarchical file systems.

The first form is less portable, since it assumes Unix-like syntax.

In general namestrings and the exact way that #P prints pathnames are
implementation dependent.  There are, in fact, differences amongst lisp
implementations on Unix hosts in how they, for example interpret a
string like "/dir1/dir2/dir3" versus "/dir1/dir2/dir3/" when the last
element names a directory.

Pathname structures are documented in the CL spec.  Namestring formats
would have to be documented in the implementation documentation.


-- 
Thomas A. Russ,  USC/Information Sciences Institute
From: Pascal J. Bourguignon
Subject: Re: <pathname-directory>/sub/dir
Date: 
Message-ID: <7c8wy5qcp3.fsf@pbourguignon.anevia.com>
danb <·········@gmail.com> writes:

>> danb <·········@gmail.com> writes:
>> > How do you create a subdirectory of another pathname
>> > directory?
>
> On May 20, 8:21 am, Zach Beane <····@xach.com> wrote:
>>   (merge-pathnames #p"sub/dir/" existing-pathname)
>>   (merge-pathnames (make-pathname :directory '(:relative "sub" "dir"))
>>                    existing-pathname)
>
> Thanks, Zach.  How portable is that, and are the
> directory and namestring formats documented somewhere?

It's very portable, as long as the target file system supports
subdirectories. Also, modulo the case.  Portable pathnames only use
uppercase.


And if by "create" you meant create it on the file system, then:

(ensure-directories-exist
 (merge-pathnames
  (make-pathname :directory '(:relative "SUB" "DIR") 
                 :name "DUMMY" :type "DAT" ;<- needed by ensure-directories-exist
                 :case :common)            ;<- the 'portable' flag.
  existing-pathname
  nil))                            ;<- another 'portable' flag, AFAIK.



-- 
__Pascal Bourguignon__
From: danb
Subject: Re: <pathname-directory>/sub/dir
Date: 
Message-ID: <8d911888-3cfe-4ad1-a832-fa016a889b66@d19g2000prm.googlegroups.com>
> >> danb <·········@gmail.com> writes:
> >> > How do you create a subdirectory of another pathname
> >> > directory?

On May 20, 9:20 am, ····@informatimago.com (Pascal J. Bourguignon)
wrote:
> And if by "create" you meant create it on the file system

No, I just want to read existing (sub)directories.
Anyway, I finally found the hyperspec page on
directory syntax.  Thanks for the help, everybody.

--Dan

------------------------------------------------
Dan Bensen  http://www.prairienet.org/~dsb/

cl-match:  expressive pattern matching in Lisp
http://common-lisp.net/project/cl-match/
From: Richard M Kreuter
Subject: Re: <pathname-directory>/sub/dir
Date: 
Message-ID: <87abilf018.fsf@progn.net>
Zach Beane <····@xach.com> writes:
> danb <·········@gmail.com> writes:
>
>> How do you create a subdirectory of another pathname
>> directory?
>
> I often use something like this:
>
>   (merge-pathnames #p"sub/dir/" existing-pathname)
>
> Or:
>
>   (merge-pathnames (make-pathname :directory '(:relative "sub" "dir"))
>                    existing-pathname)

These fragments might have the right effect under most circumstances,
but without context they can go wrong in different ways and at
different times if various pathnames have different hosts than the
programmer expected:

* the first fragment can fail to parse if *DEFAULT-PATHNAME-DEFAULTS*
  has the wrong kind of pathname-host at read-time, and might do
  something implementation-dependent at run-time if the host component
  of EXISTING-PATHNAME differs from the host of whatever
  "#p\"sub/dir/\"" parsed to (e.g., if EXISTING-PATHNAME comes from a
  random source).

* The second fragment can do something implementation-dependent if
  *DEFAULT-PATHNAME-DEFAULTS* has a different host from
  EXISTING-PATHNAME at run-time.

So if you want to rely on namestring parsing, I think it marginally
better to defer it to runtime, like this

  (let ((*default-pathname-defaults* existing-pathname))
    (merge-pathnames "sub/dir/"))

assuming that EXISTING-PATHNAME is a pathname on something like a Unix
file system.

For the second form, if using MAKE-PATHNAME is meant to buy you
anything over parsing a physical pathname namestring, it would not be
quite right to say

  (let ((*default-pathname-defaults* existing-pathname))
    (merge-pathnames (make-pathname :directory '(:relative "sub" "dir"))))

because this is only correct if EXISTING-PATHNAME is a pathname on a
host whose customary case is lower case.  So for maximal fussiness
points (but somewhat reduced de facto portability, unfortunately),
ISTM the second form is supposed to be

  (let ((*default-pathname-defaults* existing-pathname))
    (merge-pathnames (make-pathname :directory '(:relative "SUB" "DIR")
                                    :case :common)))

--
RmK