Next: , Previous: , Up: File Names   [Contents][Index]


35.8.1 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, SXEmacs 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.

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.

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.

(file-name-directory "lewis/foo")  ; Unix example
     ⇒ "lewis/"
(file-name-directory "foo")        ; Unix example
     ⇒ nil
Function: file-name-nondirectory filename

This function returns the nondirectory part of filename.

(file-name-nondirectory "lewis/foo")
     ⇒ "foo"
(file-name-nondirectory "foo")
     ⇒ "foo"
Function: file-name-sans-versions filename &optional keep-backup-version

This function returns filename without any file version numbers, backup version numbers, or trailing tildes.

If keep-backup-version is non-nil, we do not remove backup version numbers, only true file version numbers.

(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"
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"

Next: , Previous: , Up: File Names   [Contents][Index]