Sign in Join

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

Mailing lists / fpc-pascal / 2019-04

CopyFile for FreePascal without Lazarus?

9 messages · 7 people · –

Reply by email Subscribe to this list Your subscription

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

James Richters
to leledumbo

How would I use this LazUtils Package with just FPC? Is there way to download it by itself? Or would I have to Install Lazarus somewhere, go find the unit and copy it in with all my FPC Units? I was hoping to do this without doing something like that because then every time I install a new version of FPC, I would have to go back and copy the other units back in, which I probably wouldn’t remember to do right away, but later I would be wondering why I can't re-compile a program used to work that used the other units and then hopefully I would remember where they came from and how and where to copy them.

James

Earlier message 15 lines
-----Original Message----- From: fpc-pascal On Behalf Of leledumbo via fpc-pascal Sent: Thursday, April 18, 2019 2:45 AM To: Cc: leledumbo Subject: Re: [fpc-pascal] CopyFile for FreePascal without Lazarus? > but that seems to only work with Lazarus. The unit is part of LazUtils package. It has no dependency on other packages but indeed can't be used as a standalone unit, you need other units from the same package but that's all. -- Sent from: http://free-pascal-general.1045716.n5.nabble.com/

Reply by email

Benito van der Zander
to James Richters: Is there a copyfile for Freepascal I can use without installing Lazarus? I found:…

Hi James,

I have just copied the function from Lazarus to my project.

Two days ago I even copied it in a new file:
http://hg.benibela.de/internettools/file/f379759c52b9/data/xquery.internals.lclexcerpt.pas

Best,
Benito

James Richters wrote 15 lines
Is there a copyfile for Freepascal I can use without installing Lazarus? I found: http://wiki.freepascal.org/CopyFile but that seems to only work with Lazarus. I just want to make a copy of a file into a different directory and maintain it's timestamps etc Any suggestions? James _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply by email

Graeme Geldenhuys
to James Richters: How would I use this LazUtils Package with just FPC? Is there way to download it by…
James Richters wrote
How would I use this LazUtils Package with just FPC?

And with all that discussion and time gone by, you could have simply implemented it yourself using TFileStream or something like that.

eg:

const
  cBlockSize=16384; // size of block if copyfile
function CopyFile(const sSrc, sDst: String; bAppend: Boolean): Boolean;
var
  src: TFileStream = nil;
  dst: TFileStream = nil;
  iDstBeg:Integer; // in the append mode we store original size
  Buffer: PChar = nil;
begin
  Result:=False;
  if not FileExists(sSrc) then
    Exit; //==>
  GetMem(Buffer,cBlockSize+1);
  try
    try
      src:=TFileStream.Create(sSrc,fmOpenRead or fmShareDenyNone);
      if not Assigned(src) then
        Exit;
      if bAppend then
      begin
        dst:=TFileStream.Create(sDst,fmOpenReadWrite);
        dst.Seek(0,soFromEnd); // seek to end
      end
      else
        dst:=TFileStream.Create(sDst,fmCreate);
      if not Assigned(dst) then
        Exit;
      iDstBeg:=dst.Size;
      // we dont't use CopyFrom, because it's alocate and free buffer
every time is called
      while (dst.Size+cBlockSize)<= (src.Size+iDstBeg) do
      begin
        Src.ReadBuffer(Buffer^, cBlockSize);
        dst.WriteBuffer(Buffer^, cBlockSize);
      end;
      if (iDstBeg+src.Size)>dst.Size then
      begin
        src.ReadBuffer(Buffer^, src.Size+iDstBeg-dst.size);
        dst.WriteBuffer(Buffer^, src.Size+iDstBeg-dst.size);
      end;
      // unix only - if we want to copy file attributes and permissions
//      Result := FileCopyAttr(sSrc, sDst, gDropReadOnlyFlag); // chmod,
chgrp
    except
      on EStreamError do
        TfpgMessageDialog.Critical('Error', Format('Cannot copy file
<%s> to <%s>' , [sSrc, sDst]));
    end;
  finally
    if assigned(src) then
      FreeAndNil(src);
    if assigned(dst) then
      FreeAndNil(dst);
    if assigned(Buffer) then
      FreeMem(Buffer);
  end;
end;

Regards,
Graeme

Reply by email

Joost van der Sluis
to James Richters: How would I use this LazUtils Package with just FPC? Is there way to download it by…

Op 18-04-19 om 13:04 schreef James Richters:

How would I use this LazUtils Package with just FPC? Is there way to download it by itself? Or would I have to Install Lazarus somewhere, go find the unit and copy it in with all my FPC Units?

Lazutils could also be installed with Fppkg. Just download the sources, locate the fpmake.pp (components/lazutils) make sure that that directory is the current directory and run 'fppkg install'.

Thereafter you can use the Lazutils-units in all your fpc-applications.

If you update your compiler (trunk of fixes), call 'fppkg fixbroken' to re-compile the packages which are installed.

If you update to a really new version of the compiler, you have to install the package again.

Regards,

Joost.

http://lazarussupport.com - Your donation helps to push Free Pascal and Lazarus forwards.

Reply by email

Darius Blaszyk
to Joost van der Sluis

Here’s another implementation using blockread and blockwrite. The main thing missing is setting the file attributes on *nix systems.

Rgds Darius

https://github.com/daar/pmake/blob/master/pmake/pmake_utilities.pas

Verstuurd vanaf mijn iPhone

Show quoted text 22 lines
Op 20 apr. 2019 om 11:23 heeft Joost van der Sluis het volgende geschreven: Op 18-04-19 om 13:04 schreef James Richters: > How would I use this LazUtils Package with just FPC? Is there way to download it by itself? Or would I have to Install Lazarus somewhere, go find the unit and copy it in with all my FPC Units? Lazutils could also be installed with Fppkg. Just download the sources, locate the fpmake.pp (components/lazutils) make sure that that directory is the current directory and run 'fppkg install'. Thereafter you can use the Lazutils-units in all your fpc-applications. If you update your compiler (trunk of fixes), call 'fppkg fixbroken' to re-compile the packages which are installed. If you update to a really new version of the compiler, you have to install the package again. Regards, Joost. -- http://lazarussupport.com - Your donation helps to push Free Pascal and Lazarus forwards. _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply by email