COPYFILES Method (System)
Description
Copies files to a specified location, optionally showing a progress information and allowing an Undo operation.
Syntax
SuccessFlag = Exec_Method( "FILESYSTEM", "COPYFILES", FilesFrom, FilesTo, CopyFilesOptions )
Parameters
Name | Required | Description |
---|---|---|
FilesFrom | Yes | @fm-delimited list of files to copy. Wildcard characters are allowed. |
FileTo | Yes | Fully qualified path of the location to copy the files to, or an @fm-delimited list of destination files. In the latter case the number of file names must match exactly the number of file names specified in the "FilesFrom" parameter. |
CopyFilesOptions | No | Contains an @Fm-delimited dynamic array of options that control the behavior of the copy operation: <1> Allow undo <2> Allow UI <3> Parent window ID <4> Progress dialog title <5> Allow confirmations |
Returns
TRUE$ if the copy was performed successfully, or FALSE$ if an error occurred. If the case of the latter event the FILEOPRESULT property may be used to obtain more details regarding the failure.
Remarks
The CopyFilesOptions argument is composed of five fields which control the behavior of the copy operation – each field is described fully below:
Field | Name | Description |
---|---|---|
<1> | Allow undo | If TRUE$ then save Undo information. Defaults to FALSE$. |
<2> | Allow UI | If TRUE$ then allow any appropriate dialogs to be displayed such as progress and error information. Defaults to FALSE$. |
<3> | Parent window ID | Specifies the name of a WINDOW object to use as the parent for any dialogs displayed during the copy operation. |
<4> | Progress dialog title | Text to display in the progress dialog during the copy operation. |
<5> | Allow confirmations | If TRUE$ then allow the user to respond to any confirmation dialogs presented during the copy operation. Defaults to FALSE$. |
The COPYFILES method is basically a wrapper around the SHFileOperation Windows API function, so it is worth examining at the documentation for this on the MSDN website to get a better idea of the capabilities of this method.
You should use fully qualified path names with this method. Using it with relative path names is not thread safe.
Equated constants for use with the COPYFILES method can be found in the PS_FILESYSTEM_EQUATES insert record.
Example
// Use the FILESYSTEM COPYFILES method to copy all files in a folder to // a specified destination folder using wildcard characters, showing any // progress information, but not allowing the user to override any // conflicts. $Insert PS_FileSystem_Equates $Insert Logical FilesFrom = "c:\my_data\aug_2017\*.*" FilesTo = "c:\backup\backup_data\aug_2017" CopyOptions = "" CopyOptions<PS_CPF_ALLOWUNDO$> = TRUE$ ; // Save Undo info CopyOptions<PS_CPF_ALLOWUI$> = TRUE$ ; // Show dialogs CopyOptions<PS_CPF_PARENTWINDOW$> = @Window CopyOptions<PS_CPF_PROGRESSTITLE$> = "Copying data to backup folder" CopyOptions<PS_CPF_ALLOWCONFIRM$> = FALSE$ If Exec_Method( "FILESYSTEM", "COPYFILES", FilesFrom, FilesTo, CopyOptions ) Then // Copied OK - data is now in: "c:\backup\backup_data\aug_2017" End Else ErrorInfo = Get_Property( "FILESYSTEM", "FILEOPRESULT" ) ErrorCode = ErrorInfo<PS_FOR_ERRORCODE$> ErrorText = ErrorInfo<PS_FOR_ERRORTEXT$> End // Use the FILESYSTEM COPYFILES method to copy specfic files in a folder to // a specified destination folder showing any progress information, but not // allowing the user to override any conflicts. DirFrom = "c:\my_data\aug_2017\" DirTo = "c:\backup\backup_data\aug_2017\" FileNames = "book1.xls" FileNames<-1> = "book2.xls" FilesFrom = "" FilesTo = "" XCount = FieldCount( FileNames, @fm ) For X = 1 To XCount FilesFrom<x> = DirFrom : FileNames<x> FilesTo<x> = DirTo : FileNames<x> Next CopyOptions = "" CopyOptions<PS_CPF_ALLOWUNDO$> = TRUE$ ; // Save Undo info CopyOptions<PS_CPF_ALLOWUI$> = TRUE$ ; // Show dialogs CopyOptions<PS_CPF_PARENTWINDOW$> = @Window CopyOptions<PS_CPF_PROGRESSTITLE$> = "Copying data to backup folder" CopyOptions<PS_CPF_ALLOWCONFIRM$> = FALSE$ If Exec_Method( "FILESYSTEM", "COPYFILES", FilesFrom, FilesTo, CopyOptions ) Then // Copied OK - data is now in: "c:\backup\backup_data\aug_2017" End Else ErrorInfo = Get_Property( "FILESYSTEM", "FILEOPRESULT" ) ErrorCode = ErrorInfo<PS_FOR_ERRORCODE$> ErrorText = ErrorInfo<PS_FOR_ERRORTEXT$> End
See Also
FILOPRESULT property.