Copy file from one folder to another. Source and destination folders must exist.

 

Syntax

function CopyFile(const sFileFrom, sFileTo:string; const bRewrite: boolean): integer;

 

Parameters and return values

Parameter

Type

Value

FileFrom

integer

conference numeric identifier (UID);

sFileTo

string

name of destination file and full path to it;

bRewrite

boolean

rewrite a file if it exists in the destination file.

 

Function result

Conference password text name. If there is no such UID or the password is not specified, the function returns an empty string.

Result

Value

0

all OK, function executed successfully;

-1

source file or folder does not exist;

-2

destination folder does not exist;

-3

file copying failure. For example, it was busy in a monopoly mode by another program or operating system, or writing is forbidden in the destination folder.

 

Example

const
  FILE_FROM = 'c:\temp\readme.txt';
  FILE_TO   = 'c:\temp\textfiles\oldfile.txt';
var
  iResult: integer;
  s: string;
begin
  mLogScript('Copying file "' + FILE_FROM + '" to "' + FILE_TO + '"', '');  
  iResult := CopyFile(FILE_FROM, FILE_TO, true);
  
    case iResult of
      0: s := 'all ok, file moved';
     -1: s := 'source file does not exist';
     -2: s := 'destination folder does not exist';
     -3: s := 'operation aborted';
    end;
    
  mLogScript(s, '');
end.

Script work result

[15:49:45] (Log "CopyFile"): Copying file "c:\temp\readme.txt" to "c:\temp\textfiles\oldfile.txt"

[15:49:45] (Log "CopyFile"): source file does not exist

[15:49:45] (Run "CopyFile"): Script operation time: 7 ms

[15:49:45] (Run "CopyFile"): Script done successfully.
 

See also

FileExists

mLogScript