Manpage Monday: copyfile(3)
copyfile(3) is an API for copying and moving files within the file-system:
DESCRIPTION
These functions are used to copy a file’s data and/or metadata. (Metadata consists of permissions, extended attributes, access control lists, and so forth.)
The
copyfile()
function can copy the namedfrom
file to the namedto
file; thefcopyfile()
function does the same, but using the file descriptors of already-opened files.
The
copyfile()
andfcopyfile()
functions can also have their behavior modified by the following flags:
COPYFILE_CHECK
Return a bitmask (corresponding to the flags argument) indicating which contents would be copied; no data are actually copied. (E.g., if
flags
was set toCOPYFILE_CHECK|COPYFILE_METADATA
, and thefrom
file had extended attributes but no ACLs, the return value would beCOPYFILE_XATTR
.)COPYFILE_PACK
Serialize the
from
file. Theto
file is an AppleDouble-format file.COPYFILE_UNPACK
Unserialize the
from
file. Thefrom
file is an AppleDouble-format file; theto
file will have the extended attributes, ACLs, resource fork, and FinderInfo data from theto
file, regardless of theflags
argument passed in.
File Manager also has APIs for copying files, in both asynchronous and synchronous flavors. Those APIs don’t provide as much control over management of metadata, but they do offer asynchronous operation, whereas the copyfile(3) APIs appear to be synchronous.
And, of course, I should mention NSWorkspace operations, which you use with the performFileOperation:source:destination:files:tag:
method. Unlike the other two, this API has been around since 10.0. On the other hand, like copyfile(3), it’s synchronous only.