码迷,mamicode.com
首页 > Windows程序 > 详细

delphi CopyFileProgressBar 拷贝文件显示进度条

时间:2018-02-15 16:55:10      阅读:245      评论:0      收藏:0      [点我收藏+]

标签:list   lock   ufs   name   phi   sage   pos   sts   not   

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 CopyFileProgressBar 拷贝文件显示进度条

标签:list   lock   ufs   name   phi   sage   pos   sts   not   

原文地址:https://www.cnblogs.com/westsoft/p/8449597.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!