Function: file-name-split
file-name-split is a byte-compiled function defined in compat-29.el.
Signature
(file-name-split FILENAME)
Documentation
[Compatibility function for file-name-split, defined in Emacs 29.1. See
(compat) Emacs 29.1' for more details.]
Return a list of all the components of FILENAME. On most systems, this will be true:
(equal (string-join (file-name-split filename) "/") filename)
Source Code
;; Defined in ~/.emacs.d/elpa/compat-30.1.0.1/compat-29.el
(compat-defun file-name-split (filename) ;; <compat-tests:file-name-split>
"Return a list of all the components of FILENAME.
On most systems, this will be true:
(equal (string-join (file-name-split filename) \"/\") filename)"
(let ((components nil))
;; If this is a directory file name, then we have a null file name
;; at the end.
(when (directory-name-p filename)
(push "" components)
(setq filename (directory-file-name filename)))
;; Loop, chopping off components.
(while (length> filename 0)
(push (file-name-nondirectory filename) components)
(let ((dir (file-name-directory filename)))
(setq filename (and dir (directory-file-name dir)))
;; If there's nothing left to peel off, we're at the root and
;; we can stop.
(when (and dir (equal dir filename))
(push (if (equal dir "") ""
;; On Windows, the first component might be "c:" or
;; the like.
(substring dir 0 -1))
components)
(setq filename nil))))
components))