Function: dired-create-empty-file

dired-create-empty-file is an autoloaded, interactive and byte-compiled function defined in dired-aux.el.gz.

Signature

(dired-create-empty-file FILE)

Documentation

Create an empty file called FILE.

Parent directories of FILE are created as needed. Add an entry in the Dired buffer for the topmost new parent directory of FILE, if created, otherwise for the new file. If user option dired-create-empty-file-in-current-directory is non-nil, act on the current subdirectory by default, otherwise act on the default directory by default. If FILE already exists, signal an error.

View in manual

Probably introduced at or before Emacs version 27.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/dired-aux.el.gz
;;;###autoload
(defun dired-create-empty-file (file)
  "Create an empty file called FILE.
Parent directories of FILE are created as needed.
Add an entry in the Dired buffer for the topmost new parent
directory of FILE, if created, otherwise for the new file.
If user option `dired-create-empty-file-in-current-directory' is
non-nil, act on the current subdirectory by default, otherwise act on
the default directory by default.
If FILE already exists, signal an error."
  (interactive
   (list (read-file-name "Create empty file: "
                         (and dired-create-empty-file-in-current-directory
                              (dired-current-directory))))
   dired-mode)
  (let* ((expanded (expand-file-name file))
         new)
    (if (file-exists-p expanded)
        (error "Cannot create file %s: file exists" expanded))
    (setq new (dired--find-topmost-parent-dir expanded))
    (make-empty-file file 'parents)
    (when new
      (dired-add-file new)
      (dired-move-to-filename))))