Find common directory path: Difference between revisions
Content deleted Content added
Added Common Lisp |
|||
Line 584: | Line 584: | ||
"/home/user1/tmp/covert/operator" |
"/home/user1/tmp/covert/operator" |
||
"/home/user1/tmp/coven/members"]))</lang> |
"/home/user1/tmp/coven/members"]))</lang> |
||
=={{header|Common Lisp}}== |
|||
<lang lisp> |
|||
(defun common-directory-path (&rest paths) |
|||
(do* ((pathnames (mapcar #'(lambda (path) (cdr (pathname-directory (pathname path)))) paths)) ; convert strings to lists of subdirectories |
|||
(rem pathnames (cdr rem)) |
|||
(pos (length (first rem))) ) ; position of first mismatched element |
|||
((null (cdr rem)) (make-pathname :directory (cons :absolute (subseq (first pathnames) 0 pos)))) ; take the common sublists and convert back to a pathname |
|||
(setq pos (min pos (mismatch (first rem) (second rem) :test #'string-equal))) )) ; compare two paths |
|||
</lang> |
|||
(common-directory-path "/home/user1/tmp/coverage/test" "/home/user1/tmp/covert/operator" "/home/user1/tmp/coven/members") |
|||
==> #P"/home/user1/tmp/" |
|||
=={{header|D}}== |
=={{header|D}}== |