Next: , Up: Files   [Contents][Index]


5.26.1 File Names

A file name is a string identifying an individual file (or directory) in the filing system (i.e. the disk). The exact syntax of file names depends on the operating system. There are several functions for manipulating file names.

Function: file-name-absolute-p file-name

Returns true when file-name is not specified relative to the current directory.

Function: file-name-directory file-name

This function returns the directory part of the file name string file-name. This is the substring of file-name defining the directory containing the file.

(file-name-directory "/tmp/foo")
    ⇒ "/tmp/"

(file-name-directory "foo")
    ⇒ ""

(file-name-directory "foo/bar/")
    ⇒ "foo/bar/"
Function: file-name-nondirectory file-name

Returns the substring of the file name file-name which is not the directory part.

(file-name-nondirectory "/tmp/foo")
    ⇒ "foo"

(file-name-nondirectory "foo")
    ⇒ "foo"

(file-name-nondirectory "foo/bar/")
    ⇒ ""
Function: file-name-as-directory file-name

Returns a string through which the item in the file system named by file-name can be referred to as a directory.

(file-name-as-directory "./foo")
    ⇒ "./foo/"

(file-name-as-directory "./foo/")
    ⇒ "./foo/"
Function: directory-file-name directory-name

Returns a string through which the directory named by directory-name can be referred to as a file.

(directory-file-name "./foo/")
    ⇒ "./foo"

(directory-file-name "./foo")
    ⇒ "./foo"
Function: expand-file-name file-name #!optional base-dir

Expands file-name assuming that it specifies a file relative to base-dir. If base-dir is undefined it is taken as the current value of the default-directory variable. While expanding the file name, any obvious simplifications will be performed (e.g. on Unix the removal of "." and ".." where possible).

Note that the returned file name will only be absolute if one of the following conditions is met:

  1. base-dir (or default-directory) is absolute,
  2. file-name is already absolute.
(expand-file-name "foo" "./bar")
    ⇒ "bar/foo"

Note for file handler implementors: when a handler is called for the expand-file-name operation, it will only ever receive one argument, the already expanded file name. The only action that may be need to be taken is to simplify the file name (e.g. removing . and .. entries or whatever).

Function: canonical-file-name file-name

This function returns the canonical name of the file referred to by the string file-name. The canonical name of a file is defined such that two files can be compared simply by comparing their canonical names; if the names match, they refer to the same file.

(Note that the opposite isn’t always true, if two canonical names don’t match the files could still be the same, for example via hard links. On most operating systems, symbolic links will be expanded where possible.

(canonical-file-name "foo")
    ⇒ "/home/john/src/librep/man/foo"
Function: local-file-name file-name

Librep supports extensible file handling (see File Handlers), so file names may refer to files not residing in the system’s local file structure, and thus which are unavailable to other programs.

This function returns either the absolute name of the file file-name, if it is found in the local system, or false, if the file does not.

(local-file-name "foo")
    ⇒ "/home/john/src/librep/man/foo"

(local-file-name "/john@tango:foo")
    ⇒ ()
Function: make-temp-name

This function returns the name of a file which, when created, may be used for temporary storage. Each time this function is called a unique name is computed.

(make-temp-name)
    ⇒ "/tmp/00088aaa"

(make-temp-name)
    ⇒ "/tmp/00088baa"
Variable: default-directory

This variable names the current working directory. All relative file names are interpreted starting from this location in the file system.


Next: , Up: Files   [Contents][Index]