Go to the first, previous, next, last section, table of contents.


File Name Components

The operating system groups files into directories. To specify a file, you must specify the directory and the file's name within that directory. Therefore, Emacs considers a file name as having two main parts: the directory name part, and the nondirectory part (or file name within the directory). Either part may be empty. Concatenating these two parts reproduces the original file name.

On Unix, the directory part is everything up to and including the last slash; the nondirectory part is the rest. The rules in VMS syntax are complicated.

For some purposes, the nondirectory part is further subdivided into the name proper and the version number. On Unix, only backup files have version numbers in their names. On VMS, every file has a version number, but most of the time the file name actually used in Emacs omits the version number, so that version numbers in Emacs are found mostly in directory lists.

Function: file-name-directory filename
This function returns the directory part of filename (or nil if filename does not include a directory part). On Unix, the function returns a string ending in a slash. On VMS, it returns a string ending in one of the three characters `:', `]', or `>'.

(file-name-directory "lewis/foo")  ; Unix example
     => "lewis/"
(file-name-directory "foo")        ; Unix example
     => nil
(file-name-directory "[X]FOO.TMP") ; VMS example
     => "[X]"

Function: file-name-nondirectory filename
This function returns the nondirectory part of filename.

(file-name-nondirectory "lewis/foo")
     => "foo"
(file-name-nondirectory "foo")
     => "foo"
;; The following example is accurate only on VMS.
(file-name-nondirectory "[X]FOO.TMP")
     => "FOO.TMP"

Function: file-name-sans-versions filename
This function returns filename with any file version numbers, backup version numbers, or trailing tildes deleted.

(file-name-sans-versions "~rms/foo.~1~")
     => "~rms/foo"
(file-name-sans-versions "~rms/foo~")
     => "~rms/foo"
(file-name-sans-versions "~rms/foo")
     => "~rms/foo"
;; The following example applies to VMS only.
(file-name-sans-versions "foo;23")
     => "foo"

Function: file-name-sans-extension filename
This function returns filename minus its "extension," if any. The extension, in a file name, is the part that starts with the last `.' in the last name component. For example,

(file-name-sans-extension "foo.lose.c")
     => "foo.lose"
(file-name-sans-extension "big.hack/foo")
     => "big.hack/foo"


Go to the first, previous, next, last section, table of contents.