Copy File

var
  Buf: array[1..1024] of Char;
  ReadNum, WriteNum: Integer;
  Fs, Fd: file of byte;
  FileLength: Integer;
begin

  AssignFile(Fs, Edt1.text);
  Reset(Fs);
  AssignFile(Fd, Edt2.Text);
  Rewrite(Fd);
  FileLength := Filesize(Fs);
  G1.MinValue := 0;
  G1.MaxValue := FileLength;
  while FileLength > 0 do
  begin
    g1.Show;
    Application.ProcessMessages;
    Btn1.Enabled := False;
    BlockRead(Fs, buf, SizeOf(buf), ReadNum);
    BlockWrite(Fd, buf, ReadNum, writeNum);
    FileLength := FileLength - ReadNum;
    Lbl1.Caption := '[WriteNum] :' + IntToStr(WriteNum);
    Lbl3.Caption := '[ReadNum] :' + IntToStr(ReadNum);
    g1.Progress := G1.Progress + Readnum;
    Lbl2.caption := '捕捉进度: ' + inttostr(g1.PercentDone) + '%';
    Lbl5.Caption := '已经复制: ' + Inttostr((g1.Progress) div 1024 div 1024) + 'MB';
    Application.Title := '已经完成: ' + inttostr(g1.PercentDone) + '%';
    if ReadNum <> WriteNum then
      ShowMessage('出错了,磁盘空间不足');
  end;
  CloseFile(Fs);
  CloseFile(Fd);
  Application.Title := '已经完成';
  Beep;
  ShowMessage('完成');
  G1.Hide;
  Application.Title := 'CopyFile';
  Btn1.Enabled := True;
  G1.MaxValue := 0;
end;

procedure TForm1.btn2Click(Sender: TObject);
begin
  dlgOpen1.Execute;
  Edt1.Text := dlgOpen1.FileName;
end;

procedure TForm1.btn3Click(Sender: TObject);
begin
  dlgOpen1.Execute;
  Edt2.Text := dlgOpen1.FileName;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  g1.Hide;
end;

posted on 2010-11-23 18:57  haiou327'Blog  阅读(129)  评论(0)    收藏  举报

导航