FileCon.CopyFile
When a File Definition is used with an Action, the CopyFile function can be called to create a copy of a file to a specified location and with a specified name.
CopyFile returns True if the file copying is successful, but CopyFile returns False if the copying fails.
CopyFile will fail if the specified values are not allowed as a file path or file name.
The CopyFile function does not realign the File Con to the new file.
Any further functionality like Transports or MoveToAudit will continue to use the original file.
If the target directory path does not exist, Statelake will attempt to create it automatically.
Other file utility functions can be reviewed at File Functions.
For file activities that do not involve any source or destination files, please reference Windows File Functions.
Declaration: function CopyFile (const aDestPath, aDestName: string): boolean;
An example, showing CopyFile in use.
procedure
OnStartMapEvent;
var
vFilePath, vFileName:
string
;
vCopiedOK:
boolean
;
begin
//split full file name into path and name portions ...
vFilePath := ExtractFilePath(Source
.
FileCon
.
CurrentFileName);
vFileName := ExtractFileName(Source
.
FileCon
.
CurrentFileName);
//place a copy of the file in a different directory ...
vCopiedOK := Source
.
FileCon
.
CopyFile(vFilePath + 'SpareCopy\', vFileName);
if
vCopiedOK
then
LogInfo(
'Source file has been copied'
)
else
LogError(
'Error creating copy of file'
);
end
;