delphi CopyFileProgressBar 拷贝文件显示进度条


本文整理自网络,侵删。

 

CopyFileProgressBar(pwidechar(ListBox1.Items.Strings[I]),pwidechar(NewDir+'\'+ExtractFileName(ListBox1.Items.Strings[I])));

 

procedure CopyFileProgressBar(getPath,setPath:string);

var

  getStream,setStream: TFileStream;

  num, n: Integer;

  buf: PByte;

  BufSize,block: Integer;

begin

  if not FileExists(getPath) then

  begin

   // ShowMessage('源文件不存在');

   // Exit;

  end;

  getStream := TFileStream.Create(getPath, fmOpenRead or fmShareExclusive);

  setStream := TFileStream.Create(setPath, fmCreate);

  num := getStream.Size;

  setStream.Size := num;

  getStream.Position := 0;

  setStream.Position := 0;

  BufSize := num;

  block := BufSize div 100;

  GetMem(buf, BufSize);

  form1.ProgressBar1.Max := 100;

  form1.ProgressBar1.Min := 0;

  form1.ProgressBar1.Position := 0;

  while num <> 0 do

  begin

    Application.ProcessMessages;

    n := block;

    if n > num then n := num;

    getStream.ReadBuffer(buf^, n);

    setStream.WriteBuffer(buf^, n);

    form1.ProgressBar1.Position := Trunc((1 - num / BufSize) * 100);

    Dec(num, n);

  end;

  FreeMem(buf, BufSize);

  getStream.Free;

  setStream.Free;

  //ShowMessage('复制完毕');

  form1.ProgressBar1.Position := 0;

end;

相关阅读 >>

Delphi 调用相应程序打开网址

Delphi 不用控件用函数实现发email

Delphi richedit控件的用法

Delphi exe文件自效验

Delphi 在datasnap中使用firedac

Delphi 获取jpg文件宽度高度的方法

Delphi firedac连接mysql的时候报错

Delphi 判断目录是否有写入权限

如何将string变量赋值给pchar变量

Delphi 遍历控件

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...