Function: delete-file
delete-file is an interactive and byte-compiled function defined in
files.el.gz.
Signature
(delete-file FILENAME &optional TRASH)
Documentation
Delete file named FILENAME. If it is a symlink, remove the symlink.
If file has multiple names, it continues to exist with the other names.
TRASH non-nil means to trash the file instead of deleting, provided
delete-by-moving-to-trash is non-nil.
When called interactively, TRASH is t if no prefix argument is given. With a prefix argument, TRASH is nil.
Other relevant functions are documented in the file group.
Probably introduced at or before Emacs version 1.6.
Key Bindings
Shortdoc
;; file
(delete-file "/tmp/foo")
Source Code
;; Defined in /usr/src/emacs/lisp/files.el.gz
(defun delete-file (filename &optional trash)
"Delete file named FILENAME. If it is a symlink, remove the symlink.
If file has multiple names, it continues to exist with the other names.
TRASH non-nil means to trash the file instead of deleting, provided
`delete-by-moving-to-trash' is non-nil.
When called interactively, TRASH is t if no prefix argument is given.
With a prefix argument, TRASH is nil."
(interactive (list (read-file-name
(if (and delete-by-moving-to-trash (null current-prefix-arg))
"Move file to trash: " "Delete file: ")
nil default-directory (confirm-nonexistent-file-or-buffer))
(null current-prefix-arg)))
(if (and (file-directory-p filename) (not (file-symlink-p filename)))
(signal 'file-error (list "Removing old name: is a directory" filename)))
(let* ((filename (expand-file-name filename))
(handler (find-file-name-handler filename 'delete-file)))
(cond (handler (funcall handler 'delete-file filename trash))
((and delete-by-moving-to-trash trash) (move-file-to-trash filename))
(t (delete-file-internal filename)))))