<?xml version="1.0"?>
<paste-with-annotations>
  <paste>
    <number>
      <integer>53964</integer>
    </number>
    <user>
      <string>baggles</string>
    </user>
    <title>
      <string>relative-pathname</string>
    </title>
    <contents>
      <string>
(defun relative-pathname (base path)
  &quot;Taking two true pathnames, return base relative to path.&quot;
  (let ((base (merge-pathnames base))
        (path (merge-pathnames path)))
    (if (and (eql (pathname-host base)
                  (pathname-host path))
             (eql (pathname-device base)
                  (pathname-device path)))
        (let ((base-directory (copy-list (pathname-directory base)))
              (path-directory (copy-list (pathname-directory path))))
          (loop while (equal (car base-directory)
                             (car path-directory))
             do (pop base-directory)
             (pop path-directory))
          (make-pathname
           :directory
           (nconc (list :relative) 
                  (when base-directory
                    (loop repeat (length base-directory) collecting :up))
                  path-directory)
           :defaults path))
        path)))

WVR&gt; (relative-pathname #P&quot;/a/b/c/&quot; #P&quot;/a/b/d/e&quot;)
#P&quot;../d/e&quot;
WVR&gt; (relative-pathname #P&quot;/a/b/c/&quot; #P&quot;/a/b/c/d/e&quot;)
#P&quot;d/e&quot;</string>
    </contents>
    <universal-time>
      <integer>3408976072</integer>
    </universal-time>
    <channel>
      <string>#lispcafe</string>
    </channel>
    <colorization-mode>
      <string></string>
    </colorization-mode>
    <maybe-spam>
      <null/>
    </maybe-spam>
    <is-unicode>
      <null/>
    </is-unicode>
  </paste>
  <annotation>
    <number>
      <integer>1</integer>
    </number>
    <user>
      <string>baggles</string>
    </user>
    <title>
      <string>relative-pathname</string>
    </title>
    <contents>
      <string>(defun relative-pathname (base path)
  &quot;Taking two true pathnames, return base relative to path.&quot;
  (let ((base (merge-pathnames base))
        (path (merge-pathnames path)))
    (if (and (eql (pathname-host base)
                  (pathname-host path))
             (eql (pathname-device base)
                  (pathname-device path)))
        (let ((base-directory (pathname-directory base))
              (path-directory (pathname-directory path)))
          (loop while (equal (car base-directory)
                             (car path-directory))
             do (pop base-directory)
             (pop path-directory))
          (make-pathname
           :directory
           (append (list :relative) 
                   (when base-directory
                     (loop repeat (length base-directory) collecting :up))
                   path-directory)
           :defaults path))
        path)))</string>
    </contents>
    <universal-time>
      <integer>3408976282</integer>
    </universal-time>
    <channel>
      <string>#lispcafe</string>
    </channel>
    <colorization-mode>
      <string></string>
    </colorization-mode>
    <maybe-spam>
      <null/>
    </maybe-spam>
    <is-unicode>
      <null/>
    </is-unicode>
  </annotation>
</paste-with-annotations>