copy-file ( from to -- )
Factor documentation > Factor handbook > Input and output > Directory manipulation > Deleting, moving, and copying files
Prev:move-files-into ( files to -- )
Next:copy-file-into ( from to -- )


Vocabulary
io.directories

Inputs and outputs
froma pathname string
toa pathname string


Word description
Copies a file.

Notes
This operation attempts to preserve the original file's attributes, however not all attributes may be preserved.

Errors
Throws an error if the file does not exist or if the copy operation fails.

Definition
USING: io.backend ;

IN: io.directories

HOOK: copy-file io-backend ( from to -- )


Methods
USING: destructors io io.directories io.encodings.binary
io.files io.pathnames kernel ;

M: object copy-file
dup parent-directory make-directories binary <file-writer>
[
swap binary <file-reader>
[ swap stream-copy ] with-disposal
] with-disposal ;


USING: generic io.backend io.directories io.files.info.unix
kernel system ;

M: unix copy-file
[ normalize-path ] bi@
[ M\ unix copy-file (call-next-method) ]
[ [ file-permissions ] dip swap set-file-permissions ] 2bi
;