Function: copy-file

copy-file is an interactive function defined in C source code.

Signature

(copy-file FILE NEWNAME &optional OK-IF-ALREADY-EXISTS KEEP-TIME PRESERVE-UID-GID PRESERVE-PERMISSIONS)

Documentation

Copy FILE to NEWNAME. Both args must be strings.

If NEWNAME is a directory name, copy FILE to a like-named file under NEWNAME. For NEWNAME to be recognized as a directory name, it should end in a slash.

This function always sets the file modes of the output file to match the input file.

The optional third argument OK-IF-ALREADY-EXISTS specifies what to do if file NEWNAME already exists. If OK-IF-ALREADY-EXISTS is nil, signal a file-already-exists error without overwriting. If OK-IF-ALREADY-EXISTS is an integer, request confirmation from the user about overwriting; this is what happens in interactive use with M-x. Any other value for OK-IF-ALREADY-EXISTS means to overwrite the existing file.

Fourth arg KEEP-TIME non-nil means give the output file the same last-modified time as the old one. (This works on only some systems.)

A prefix arg makes KEEP-TIME non-nil.

If PRESERVE-UID-GID is non-nil, try to transfer the uid and gid of FILE to NEWNAME.

If PRESERVE-PERMISSIONS is non-nil, copy permissions of FILE to NEWNAME; this includes the file modes, along with ACL entries and SELinux context if present. Otherwise, if NEWNAME is created its file permission bits are those of FILE, masked by the default file permissions.

Other relevant functions are documented in the file group.

View in manual

Probably introduced at or before Emacs version 1.6.

Key Bindings

Shortdoc

;; file
(copy-file "/tmp/foo" "/tmp/foocopy")

Source Code

C code is not yet loaded.