Function: archive-copy-file
archive-copy-file is an interactive and byte-compiled function defined
in arc-mode.el.gz.
Signature
(archive-copy-file FILES NEW-NAME)
Documentation
Copy FILES to a location specified by NEW-NAME.
FILES can be a single file or a list of files.
Interactively, FILES is the list of marked files, or the file at point if nothing is marked, and the function prompts for NEW-NAME.
Probably introduced at or before Emacs version 28.1.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/arc-mode.el.gz
(defun archive-copy-file (files new-name)
"Copy FILES to a location specified by NEW-NAME.
FILES can be a single file or a list of files.
Interactively, FILES is the list of marked files, or the file at
point if nothing is marked, and the function prompts for
NEW-NAME."
(interactive
(let ((names
(mapcar
#'archive--file-desc-ext-file-name
(or (archive-get-marked ?*) (list (archive-get-descr))))))
(list names
(read-file-name (format "Copy %s to: " (string-join names ", "))))))
(unless (consp files)
(setq files (list files)))
(when (and (> (length files) 1)
(not (file-directory-p new-name)))
(user-error "Can't copy a list of files to a single file"))
(save-excursion
(dolist (file files)
(let ((write-to (if (file-directory-p new-name)
(expand-file-name file new-name)
new-name)))
(when (and (file-exists-p write-to)
(not (yes-or-no-p (format "%s already exists; overwrite? "
write-to))))
(user-error "Not overwriting %s" write-to))
(archive-goto-file file)
(let* ((descr (archive-get-descr))
(archive (buffer-file-name))
(extractor (archive-name "extract"))
(ename (archive--file-desc-ext-file-name descr)))
(with-temp-buffer
(set-buffer-multibyte nil)
(archive--extract-file extractor archive ename)
(write-region (point-min) (point-max) write-to)))))))