Skip to content

Instantly share code, notes, and snippets.

@DeaR
Created April 25, 2012 10:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DeaR/2488639 to your computer and use it in GitHub Desktop.
Save DeaR/2488639 to your computer and use it in GitHub Desktop.
file-relative-name相当…のつもり #xyzzy
(defun relative-pathnames (fn dir)
"dirを基準にしたfnの相対パスを返す"
(if (string-equal (pathname-device #0=(merge-pathnames fn))
(pathname-device #1=(merge-pathnames dir)))
(let ((fn (split-string #0# #\/))
(dir (split-string #1# #\/)))
(dotimes (i (length fn))
(unless (string-equal (nth i fn) (nth i dir))
(return (format nil "~{~A/~}~{~A/~}~{~A~}"
(make-list (- (length dir) i) :initial-element "..")
(butlast (last fn (- (length fn) i)))
(last fn))))))
#0#))
@DeaR
Copy link
Author

DeaR commented Apr 25, 2012

間違いなく車輪の再発明…だと思う('A

@DeaR
Copy link
Author

DeaR commented Apr 25, 2012

truename だと存在しないパスの場合エラーが出ちゃうわ…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment