[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: relative pathnames



        Reply to:   RE>relative pathnames
> Two questions regarding pathnames in MCL:
> 
> 1) What is the equivalent to the Unix pathname "foo/../bar"?  I.e. how can
I
>    jump up one level in a pathname?

you can use the following function

(defun parent-dir (dir)
  (directory-namestring 
   (make-pathname :directory (butlast (pathname-directory dir)))))

(parent-dir #P"Andre:Desktop Folder: "2 strokes:T 500 Cobra.lisp")

> 2) Is it possible to make a pathname relative to the file it appears in? 
For
>    example, given a file "root:foo.lisp", can it contain (load
"bar:baz.lisp")
>    and somehow expect the system to find "root:foo:bar:baz.lisp"?

You can probably get there with a hack, but it is a lot easier to get at 
"root:bar:baz.lisp".
When yoiu load a file, the variable *load-pathname* (CLtL 2 pg 658) is bound
to
the full pathname of that file.
 From there you can easily at the directory that file is in.
Then you can concatenate the directory and filename and load the result.

However, if you're working on complex projects it might be a good idea to
take a look at one of the defsys packages that are available.

An example of code that you can use in the loaded file:

(let ((current-dir (directory-namestring *load-pathname*))
      (files (list "2-strokes:GT 750 le Mans.lisp"
                   "2-strokes:T 500 Cobra.lisp"
                   "4-strokes:Lodola 235 GT.lisp")))
  (dolist (file files)
    (load (concatenate 'string current-dir file))
    )
  )

Hope this helps,

Andre.