From: Steve Teixeira <steixeir@borland.com>
Newsgroups: comp.lang.pascal
Subject: Re: DELPHI:File Copy command
Date: 24 Apr 1995 17:27:42 GMT
Organization: Borland Intl

vdata@inforamp.net (Bryan Zarnett) wrote:
>
> Is there a command in Delphi to do a file copy? sorta like Filcopy FileA,FileB?
> can't seem to find one...grumble
> 

Since those functions are provided by the Windows API, Delphi doesn't provide them.
Here is a function from my upcoming book, Delphi Developer's Guide, which encapsulates
all that nasty API stuff into nice, pretty Object Pascal.

	-Steve Teixeira
	 steixeir@borland.com

***************
uses LZExpand;

procedure CopyFile(Source, Dest: String);
var
  SourceHand, DestHand: Integer;
  OpenBuf: TOFStruct;
begin
  Source[Ord(Source[0]) + 1] := #0;
  Dest[Ord(Dest[0]) + 1] := #0;
  SourceHand := LZOpenFile(@Source[1], OpenBuf, of_Share_Deny_Write or of_Read);
  if SourceHand = -1 then
    raise EInOutError.Create('Error opening source file');
  DestHand := LZOpenFile(@Dest[1], OpenBuf, of_Share_Exclusive or of_Write
                         or of_Create);
  if DestHand = -1 then begin
    LZClose(SourceHand);
    raise EInOutError.Create('Error opening destination file');
  end;
  try
    if LZCopy(SourceHand, DestHand) < 0 then
      raise EInOutError.Create('Error copying file');
  finally
    LZClose(SourceHand);
    LZClose(DestHand);
  end;
end;

