Function: file-name-directory

file-name-directory is a function defined in fileio.c.

Signature

(file-name-directory FILENAME)

Documentation

Return the directory component in file name FILENAME.

Return nil if FILENAME does not include a directory. Otherwise return a directory name. Given a Unix syntax file name, returns a string ending in slash.

Other relevant functions are documented in the file-name group.

View in manual

Probably introduced at or before Emacs version 1.11.

Shortdoc

;; file-name
(file-name-directory "/tmp/foo")
    => "/tmp/"
  (file-name-directory "/tmp/foo/")
    => "/tmp/foo/"

Aliases

eshell/dirname

Source Code

// Defined in /usr/src/emacs/src/fileio.c
{
  Lisp_Object handler;

  CHECK_STRING (filename);

  /* If the file name has special constructs in it,
     call the corresponding file name handler.  */
  handler = Ffind_file_name_handler (filename, Qfile_name_directory);
  if (!NILP (handler))
    {
      Lisp_Object handled_name = calln (handler, Qfile_name_directory,
					filename);
      return STRINGP (handled_name) ? handled_name : Qnil;
    }

  return file_name_directory (filename);
}