unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ComCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
btnCopyFile: TButton;
lblCopyTime: TLabel;
pgbCurrentFile: TProgressBar;
procedure btnCopyFileClick(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
// If you set the ProgressBar to Smooth it will slow the procedure extremely
// If you set the ProgressBar BarShowText to True this will not work.
procedure CopyFileWithPgB(Source, Destination: string; PgB: TProgressBar; LbL:
TLabel);
// Do FileExists before calling ________________________________________________
var
FromFile, ToFile: file of byte;
Buffer: array[0..4096] of char;
NumRead: integer;
FileLength: longint;
StartTime, EndTime: TDateTime; // Used to show the CopyTime to copy a file
begin
AssignFile(FromFile, Source);
reset(FromFile);
AssignFile(ToFile, Destination);
rewrite(ToFile);
FileLength := FileSize(FromFile);
with PgB do
begin
Max:= FileLength;
StartTime:= now; // Used to show the CopyTime to copy a file
while FileLength > 0 do
begin
BlockRead(FromFile, Buffer[0], SizeOf(Buffer), NumRead);
FileLength:= FileLength - NumRead;
BlockWrite(ToFile, Buffer[0], NumRead);
Position:= Position + NumRead;
EndTime:= now; // Used to show the CopyTime to copy a file
LbL.Caption:= FormatDateTime('hh:nn:ss', EndTime - StartTime);
Application.Processmessages;
end;
CloseFile(FromFile);
CloseFile(ToFile);
end;
end;
procedure TForm1.btnCopyFileClick(Sender: TObject);
var Source, Dest: string;
begin
// Do prechecks to make sure FileExists_________________________________________
Source:='/home/rodg/Desktop/Source/Test.mkv';
Dest:= '/home/rodg/Desktop/Destination1/Test.mkv';
pgbCurrentFile.Position:= 0;
CopyFileWithPgB(Source, Dest, pgbCurrentFile, lblCopyTime);
end;
end.