Карта сайта Kansoftware
НОВОСТИУСЛУГИРЕШЕНИЯКОНТАКТЫ
Разработка программного обеспечения
KANSoftWare

Скопировать файл с заполнением своего ProgressBara

Delphi , Файловая система , Файлы

Скопировать файл с заполнением своего ProgressBara

Автор: Xavier Pacheco

{
Copyright © 1999 by Delphi 5 Developer's Guide - Xavier Pacheco and Steve Teixeira
}

unit MainFrm;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls,
  Forms, Dialogs, StdCtrls, ComCtrls, Gauges;

type
  TMainForm = class(TForm)
    prbCopy: TProgressBar;
    btnCopy: TButton;
    procedure btnCopyClick(Sender: TObject);
  end;

var
  MainForm: TMainForm;

implementation

{$R *.DFM}

procedure TMainForm.btnCopyClick(Sender: TObject);
var
  SrcFile, DestFile: file;
  BytesRead, BytesWritten, TotalRead: Integer;
  Buffer: array[1..500] of byte;
  FSize: Integer;
begin
  { Assign both the source and destination files to their
    respective file variables }
  AssignFile(SrcFile, 'srcfile.tst');
  AssignFile(DestFile, 'destfile.tst');
  // Open the source file for read access.
  Reset(SrcFile, 1);
  try
    // Open destination file for write access.
    Rewrite(DestFile, 1);
    try
      { Encapsulate this into a try..except so that we can erase the file if
        an error occurs. }
      try
        // Initialize total bytes read to zero.
        TotalRead := 0;
        // Obtain the filesize of the source file
        FSize := FileSize(SrcFile);
        { Read SizeOf(Buffer) bytes from the source file
          and add these bytes to the destination file. Repeat this
          process until all bytes have been read from the source
          file. A progress bar is provided to show the progress of the
          copy operation. }
        repeat
          BlockRead(SrcFile, Buffer, SizeOf(Buffer), BytesRead);
          if BytesRead > 0 then
          begin
            BlockWrite(DestFile, Buffer, BytesRead, BytesWritten);
            if BytesRead <> BytesWritten then
              raise Exception.Create('Error copying file')
            else
            begin
              TotalRead := TotalRead + BytesRead;
              prbCopy.Position := Trunc(TotalRead / Fsize) * 100;
              prbCopy.Update;
            end;
          end
        until BytesRead = 0;
      except
        { On an exception, erase the destination file as it may be
          corrupt. Then re-raise the exception. }
        Erase(DestFile);
        raise;
      end;
    finally
      CloseFile(DestFile); // Close the destination file.
    end;
  finally
    CloseFile(SrcFile); // Close the source file.
  end;
end;

end.

Статья Скопировать файл с заполнением своего ProgressBara раздела Файловая система Файлы может быть полезна для разработчиков на Delphi и FreePascal.


Комментарии и вопросы


:: 2008-12-10 22:06:45 :: re:Скопировать директорию с заполнением своего ProgressBara

пользователь: vitaliy.

как скопировать директорию с заполнением своего ProgressBara


:: 2008-12-14 15:08:01 :: re:Скопировать файл с заполнением своего ProgressBara

пользователь: kan.

1. С помощью FindFirst и FindNext создаешь список файлов

if FindFirst (ldir + \'\\*.htm\', faAnyFile and not faDirectory, sr)=0 then
begin
loadcontent.add(sr.Name);//loadcontent это tstringlist
while FindNext(sr)=0 do loadcontent.add(sr.Name);
end;

2. С помощью function CopyFile(FromPath, ToPath: string): integer;, описанной http://www.kansoftware.ru/?tid=1690, копируешь файлы по одному, беря их по одному их списка loadcontent
2.1. при этом цикл у тебя будет от 0 до loadcontent.count-1
2.2. при каждой итерации двигаешь индикатор ProgressBar


Ваше мнение или вопрос к статье в виде простого текста (Tag <a href=... Disabled). Все комментарии модерируются, модератор оставляет за собой право удалить непонравившейся ему комментарий.

заголовок

e-mail

Ваше имя

Сообщение

Введите код




Материалы статей собраны из открытых источников, владелец сайта не претендует на авторство. Там где авторство установить не удалось, материал подаётся без имени автора. В случае если Вы считаете, что Ваши права нарушены, пожалуйста, свяжитесь с владельцем сайта.



:: Главная :: Файлы ::


реклама



©KANSoftWare (разработка программного обеспечения, создание программ, создание интерактивных сайтов), 2007
Top.Mail.Ru Rambler's Top100

Время компиляции файла: 2024-04-24 22:55:34
2024-04-25 03:14:11/0.0067179203033447/2