Board index » delphi » Help newbie - making copies of files

Help newbie - making copies of files

I am trying to learn Delphi 2. How do I make a copy of a file? Do open it
and use BlockRead and write to the new file using BlockWrite, or is there an
easy mathod using a procedure I don't know about?

Thank,

Brian
br...@bjcoutts.clara.net

 

Re:Help newbie - making copies of files


Hello.

You can simply use this code:
CopyFile(FromFileName, ToFileName, True);
--
Regards
Kai Inge

Brian J Coutts <br...@bjcoutts.clara.net> wrote in article
<6n3052$6c...@eros.clara.net>...

Quote
> I am trying to learn Delphi 2. How do I make a copy of a file? Do open it
> and use BlockRead and write to the new file using BlockWrite, or is there
an
> easy mathod using a procedure I don't know about?

> Thank,

> Brian
> br...@bjcoutts.clara.net

Re:Help newbie - making copies of files


In article <6n3052$6c...@eros.clara.net>,
  "Brian J Coutts" <br...@bjcoutts.clara.net> wrote:

Quote

> I am trying to learn Delphi 2. How do I make a copy of a file? Do open it
> and use BlockRead and write to the new file using BlockWrite, or is there an
> easy mathod using a procedure I don't know about?

> Thank,

> Brian
> br...@bjcoutts.clara.net

The easiest way I have found is to use two file streams.

procedure FileCopy(sSourceFile, sDestFile: string);
Var
  Source, Dest : TFileStream;
begin
  Source:= TFileStream.Create(sSourceFile, fmOpenRead);
  try
    Dest:= TFileStream..Create(sDestFile, fmOpenWrite or fmCreate);
    try
      Dest.CopyFrom(Source, Source.Size);
    finally
      Dest.Free;
    end;
  finally
    Source.Free;
  end;
end;

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum

Other Threads