Transfer a file from one folder to another with further deleting of the original file. Source and destination folders must exist.

 

Syntax

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

 

Parameters and return values

Parameter

Type

Value

sFileFrom

string

source file name and a path to it;

sFileTo

string

destination file name and a path to it;

bRewrite

boolean

rewrite a file or not (if it exists in the destination folder).

 

Function result

Result

Value

0

all OK, a file was transferred successfully;

1

all OK, a file was transferred and rewritten successfully;

-1

source file or folder does not exist;

-2

destination folder does not exist;

-3

destination file already exists , but a flag bRewrite=false and a file was not transferred;

-4

file transfer failure. For example, it was busy in a monopoly mode by another program, operating system, or this file on CD that can't be physically deleted or write.

 

Example


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


See also

FileExists

mLogScript

Created with the Personal Edition of HelpNDoc: Leave the tedious WinHelp HLP to CHM conversion process behind with HelpNDoc