Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2004-05

File copying

4 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Matthews

I'm writing code that includes file copying, but the method I'm currently using is far too slow. I'm currently just reading a file character by character, and spitting it out to another file, character by character. Unfortunately, that's brutally slow.

Any suggestions on a better method?

-Lukas

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.675 / Virus Database: 437 - Release Date: 02-May-04

Reply by email

Marc Santhoff
to Matthews
Show quoted text 6 lines
I'm writing code that includes file copying, but the method I'm currently using is far too slow. I'm currently just reading a file character by character, and spitting it out to another file, character by character. Unfortunately, that's brutally slow. Any suggestions on a better method?

As known from Borlands compilers: use "blockread" and "blockwrite" (fpc should know, doesn't it?) or do it in larger chunks and implement buffering.

HTH,
Marc

Reply by email

Matt Emson
to Matthews: I'm writing code that includes file copying, but the method I'm currently using is far…
Any suggestions on a better method?
uses
  classes, sysutils;

....

procedure CopyFile(filename, newfilename: string);
var
  oldfile, newfile: TFilestream;
begin
  oldfile := TFileStream.Create(filename, fmOpenRead); //might need
fmShareXXX style stuff too
  try
    oldfile.Position := 0; //could use TStream.Seek(..) here also..
    newfile := TFileStream.Create(newfilename, fmCreate);
    try
      newfile.CopyFrom( oldfile, oldfile.size );
    finally
      newfile.free; // be careful.. file not actually closed till this
point...
    end;
  finally
    oldfile.free; //this closes the file..
  end;
end;

No legacy Assign[File] (or rewrite etc) in sight too.

Matt

Reply by email

Jim Wilson
to Matthews: I'm writing code that includes file copying, but the method I'm currently using is far…
you wrote
I'm writing code that includes file copying, but the method I'm currently using is far too slow. I'm currently just reading a file character by character, and spitting it out to another file, character by character. Unfortunately, that's brutally slow.

I've always used blockread and blockwrite for such things. Seems to work pretty fast.

Regards,
Jim

Reply by email