Function: make-empty-file

make-empty-file is an interactive and byte-compiled function defined in files.el.gz.

Signature

(make-empty-file FILENAME &optional PARENTS)

Documentation

Create an empty file FILENAME.

Optional arg PARENTS, if non-nil then creates parent dirs as needed.

If called interactively, then PARENTS is non-nil.

Other relevant functions are documented in the file group.

View in manual

Probably introduced at or before Emacs version 27.1.

Key Bindings

Shortdoc

;; file
(make-empty-file "/tmp/foo")

Source Code

;; Defined in /usr/src/emacs/lisp/files.el.gz
(defun make-empty-file (filename &optional parents)
  "Create an empty file FILENAME.
Optional arg PARENTS, if non-nil then creates parent dirs as needed.

If called interactively, then PARENTS is non-nil."
  (interactive "FCreate empty file: \np")
  (when parents
    (when-let* ((paren-dir (file-name-directory filename)))
      (make-directory paren-dir :parents)))
  ;; The `excl' is crucial, in case someone else has created the file in
  ;; the meantime (TOCTTOU).
  (write-region "" nil filename nil 0 nil 'excl))