Platforms to show: All Mac Windows Linux Cross-Platform

CopyFileMBS class

Type Topic Plugin Version macOS Windows Linux iOS Targets
class Files MBS MacOSX Plugin 19.4 ✅ Yes ❌ No ❌ No ✅ Yes All
The class for copyfile function.

We provide a class to hold state and get event for progress.
Uses low level copyfile API from MacOS.

See copyfile man page in terminal.

  • event Progress(What as Integer, Stage as Integer, Source as String, Dest as String) as Integer
  • 4 properties
  • 2 methods
    • method CopyFile(From as FolderItem, Dest as FolderItem, flags as Integer) as Integer
    • method CopyFile(From as String, Dest as String, flags as Integer) as Integer
  • shared method ErrorMessage(error as Integer) as String
  • 35 constants

Flags

Constant Value Description
kFlagsACL 1 Copy the source file's access control lists.
kFlagsAll 15 Copy the entire file; equivalent to BitwiseOr(kFlagsMetaData, kFlagsData).
kFlagsCheck &h10000 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 to kFlagsCheck + kFlagsMetaData, and the from file had extended attributes but no ACLs, the return value would be kFlagsXAttr.)
kFlagsClone &h1000000 Try to clone the file instead. This is a best try flag i.e. if cloning fails, fallback to copying the file. This flag is equivalent to BitwiseOr(kFlagsExcl, kFlagsACL, kFlagsStat, kFlagsXAttr, kFlagsData, kFlagsNoFollowSource). more
kFlagsCloneForce &h2000000 Clone the file instead. This is a force flag i.e. if cloning fails, an error is returned. This flag is equivalent to BitwiseOr(kFlagsExcl, kFlagsACL, kFlagsStat, kFlagsXAttr, kFlagsData, kFlagsNoFollowSource). Note that if cloning is successful, progress callbacks will not be invoked. Note also that there is no support for cloning directories: if a directory is provided as the source, an error will be returned.
kFlagsData 8 Copy the source file's data.
kFlagsDataSparse &h8000000 Copy a file sparsely. This requires that the source and destination file systems support sparse files with hole sizes at least as large as their block sizes. more
kFlagsExcl &h20000 Fail if the to file already exists.
kFlagsMetaData 7 Copy the metadata; equivalent to BitwiseOr(kFlagsSecurity, kFlagsXAttr).
kFlagsMove &h100000 Unlink (using remove(3)) the from file.
No error is returned if remove(3) fails. Note that remove(3) removes a symbolic link itself, not the target of the link.
kFlagsNoFollow &hC00000 This is a convenience macro, equivalent to BitwiseOr(kFlagsNoFollowDest, kFlagsNoFollowSource).
kFlagsNoFollowDest &h80000 Do not follow the to file, if it is a symbolic link.
kFlagsNoFollowSource &h40000 Do not follow the from file, if it is a symbolic link.
kFlagsPack &h400000 Serialize the from file. The to file is an Apple-Double-format file.
kFlagsRecursive &h8000 Causes copyfile to recursively copy a hierarchy.
kFlagsRunInPlace &h4000000 If the src file has quarantine information, add the QTN_FLAG_DO_NOT_TRANSLOCATE flag to the quarantine information of the dst file. This allows a bundle to run in place instead of being translocated.
kFlagsSecurity 3 Copy the source file's POSIX and ACL information; equivalent to BitwiseOr(kFlagsStat,kFlagsACL).
kFlagsStat 2 Copy the source file's POSIX information (mode, modification time, etc.).
kFlagsUnlink &h200000 Unlink the to file before starting.
kFlagsUnpack &h800000 Unserialize the from file. The from file is an AppleDouble-format file; the to file will have the extended attributes, ACLs, resource fork, and FinderInfo data from the to file, regardless of the flags argument passed in.
kFlagsVerbose &h40000000 Verbose messages.
kFlagsXAttr 4 Copy the source file's extended attributes.

Event Return Values

Constant Value Description
kReturnContinue 0 The copy will continue as expected.
kReturnQuit 2 The data copy will be aborted; in the case of kStageProgress, result will be set to ECANCELED (89).
kReturnSkip 1 The data copy will be aborted, but without error.

Progress

Constant Value Description
kStageError 3 Indicates an error has happened at some stage.
kStageFinish 2 After copying has successfully finished.
kStageProgress 4 Copy in progress.
kStageStart 1 Before copying has begun.

What

Constant Value Description
kWhatCopyData 4 Data is copied currently.
kWhatCopyXAttr 5 Extended attributes are copied currently.
kWhatRecurseDir 2 The object being copied is a directory, and is being entered. (That is, none of the filesystem objects contained within the directory have been copied yet.)
kWhatRecurseDirCleanup 3 The object being copied is a directory, and all of the objects contained have been copied. At this stage, the destination directory being copied will have any extra permissions that were added to allow the copying will be removed.
kWhatRecurseError 0 There was an error in processing an element of the source hierarchy; this happens when fts(3) returns an error or unknown file type.
kWhatRecurseFile 1 The object being copied is a file (or, rather, something other than a directory).

This class has no sub classes.

Some examples using this class:

Blog Entries

Xojo Developer Magazine

Videos

Release notes

  • Version 19.4
    • Added CopyFileMBS class for low level Mac file copy API.

The items on this page are in the following plugins: MBS MacOSX Plugin.


Control   -   CoreAudioListenerMBS


The biggest plugin in space...