답변:
file-name-directory
요청한 내용을 수행합니다.
그러나 (file-name-directory "/home/sk/parent/")
(슬래시가있는)는 부모가 아닌 동일한 디렉토리를 반환합니다.
이것은 내가 당신이 정말로 원하는 것을 추측합니다 :
(file-name-directory (directory-file-name "/home/sk/parent/ab.el")) ; => "/home/sk/parent/"
(file-name-directory (directory-file-name "/home/sk/parent/")) ; => "/home/sk/"
(file-name-directory (directory-file-name "/home/sk/parent")) ; => "/home/sk/"
그리고 Dired + 라이브러리 는이 기능을 사용합니다 :
(defun diredp-parent-dir (file &optional relativep)
"Return the parent directory of FILE, or nil if none.
Optional arg RELATIVEP non-nil means return a relative name, that is,
just the parent component."
(let ((parent (file-name-directory (directory-file-name (expand-file-name file))))
relparent)
(when relativep
(setq relparent (file-name-nondirectory (directory-file-name parent))))
(and (not (equal parent file)) (or relparent parent))))
(defun parent-directory (dir)
(unless (equal "/" dir)
(file-name-directory (directory-file-name dir))))