CopyFile for FreePascal without Lazarus?

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

CopyFile for FreePascal without Lazarus?

Zaaphod
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  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: CopyFile for FreePascal without Lazarus?

Free Pascal - General mailing list
> 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/
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: CopyFile for FreePascal without Lazarus?

Zaaphod
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

-----Original Message-----
From: fpc-pascal <[hidden email]> On Behalf Of leledumbo via fpc-pascal
Sent: Thursday, April 18, 2019 2:45 AM
To: [hidden email]
Cc: leledumbo <[hidden email]>
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/
_______________________________________________
fpc-pascal maillist  -  [hidden email] http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: CopyFile for FreePascal without Lazarus?

Benito van der Zander
In reply to this post by Zaaphod

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 

On 18.04.2019 03:06, James Richters wrote:
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  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: CopyFile for FreePascal without Lazarus?

Graeme Geldenhuys-6
In reply to this post by Zaaphod
On 18/04/2019 12:04, 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

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: CopyFile for FreePascal without Lazarus?

Bart-48
In reply to this post by Zaaphod
On Thu, Apr 18, 2019 at 3:11 AM James Richters
<[hidden email]> wrote:
> I just want to make a copy of a file into a different directory and maintain it's timestamps etc

http://svn.code.sf.net/p/flyingsheep/code/trunk/MijnLib/fsifileutils.pp
It has a filecopy() function with progress event.
Just replace TFileStreamUTF8 with TFileStream and you'r probably done.

--
Bart
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: CopyFile for FreePascal without Lazarus?

Joost van der Sluis
In reply to this post by Zaaphod
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  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: CopyFile for FreePascal without Lazarus?

Darius Blaszyk-2
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

Op 20 apr. 2019 om 11:23 heeft Joost van der Sluis <[hidden email]> 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  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: CopyFile for FreePascal without Lazarus?

Graeme Geldenhuys-6
In reply to this post by Joost van der Sluis
On 20/04/2019 10:23, Joost van der Sluis wrote:
> Lazutils could also be installed with Fppkg.

Very good to know - thanks for mentioning that Joost. Glad to see the
fppkg is finally being used after years lying dormant.


Regards,
  Graeme

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal