Created
April 25, 2012 10:01
-
-
Save DeaR/2488639 to your computer and use it in GitHub Desktop.
file-relative-name相当…のつもり #xyzzy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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#)) |
truename
だと存在しないパスの場合エラーが出ちゃうわ…
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
間違いなく車輪の再発明…だと思う('A