How to copy files in Free Pascal

To copy files in Free Pascal, you can do it in many ways, one of them is to use TStreamFile‘s CopyFrom method.

This example could copy any type of files without changing it’s contents. But destination file information will be changed, like file name, and updated time.

var‬‬
  SourceF, DestF: TFileStream;
begin‬‬
  ‪SourceF:= TFileStream.Create('Photo.jpg', fmOpenRead);
  ‪DestF:= TFileStream.Create('PhotoCopy.jpg', fmCreate);
  ‪DestF.CopyFrom(SourceF, SourceF.Size);
  SourceF.Free;
  DestF.Free;
end;

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s