Function: make-directory
make-directory is an interactive and byte-compiled function defined in
files.el.gz.
Signature
(make-directory DIR &optional PARENTS)
Documentation
Create the directory DIR and optionally any nonexistent parent dirs.
Interactively, the default choice of directory to create is the current buffer's default directory. That is useful when you have visited a file in a nonexistent directory.
Noninteractively, the second (optional) argument PARENTS, if non-nil, says whether to create parent directories that don't exist. Interactively, this happens by default.
Return non-nil if PARENTS is non-nil and DIR already exists as a directory, and nil if DIR did not already exist but was created. Signal an error if unsuccessful.
Other relevant functions are documented in the file group.
Probably introduced at or before Emacs version 23.1.
Key Bindings
Shortdoc
;; file
(make-directory "/tmp/bar/zot/" t)
Aliases
Source Code
;; Defined in /usr/src/emacs/lisp/files.el.gz
(defun make-directory (dir &optional parents)
"Create the directory DIR and optionally any nonexistent parent dirs.
Interactively, the default choice of directory to create is the
current buffer's default directory. That is useful when you have
visited a file in a nonexistent directory.
Noninteractively, the second (optional) argument PARENTS, if
non-nil, says whether to create parent directories that don't
exist. Interactively, this happens by default.
Return non-nil if PARENTS is non-nil and DIR already exists as a
directory, and nil if DIR did not already exist but was created.
Signal an error if unsuccessful."
(interactive
(list (read-file-name "Make directory: " default-directory default-directory
nil nil)
t))
;; If default-directory is a remote directory,
;; make sure we find its make-directory handler.
(setq dir (expand-file-name dir))
(let ((handler (find-file-name-handler dir 'make-directory)))
(if handler
(funcall handler 'make-directory dir parents)
(if (not parents)
(make-directory-internal dir)
(let ((dir (directory-file-name (expand-file-name dir)))
already-dir create-list parent)
(while (progn
(setq parent (directory-file-name
(file-name-directory dir)))
(condition-case ()
(ignore (setq already-dir
(files--ensure-directory dir)))
(error
;; Do not loop if root does not exist (Bug#2309).
(not (string= dir parent)))))
(setq create-list (cons dir create-list)
dir parent))
(dolist (dir create-list)
(setq already-dir (files--ensure-directory dir)))
already-dir)))))