进度复制用哪种方法速度最快,最不容易出错?请给个例子,谢谢

解决方案 »

  1.   

    BlockRead()和BlockWrite()就可以,一般是用这个来复制文件,可以显示出复制进度
      

  2.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        Edit1: TEdit;
        Edit2: TEdit;
        Label1: TLabel;
        Label2: TLabel;
        Button2: TButton;
        Button3: TButton;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
        procedure Button3Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    {var
      f,df:file;
      tf,td,count:integer;
      but:array[1..2048]of char;
      m,m1:boolean;}
    var
      treadf,twritef:file;
      tinfof:textfile;
      numr,numw:integer;
      buf:array[1..2048]of char;
      path,fname,exfname:string;
    begin
      path:='i:\';  if fileexists(edit1.Text)then
        begin
          assignfile(tinfof,edit1.Text);
          reset(tinfof);
          readln(tinfof,fname);
          
          exfname:=extractfilename(fname);   //获取文件名,并加入“合并后的”这个特定标志;
          exfname:='合并后的'+copy(exfname,0,length(exfname)-1);
          closefile(tinfof);      assignfile(tinfof,edit1.Text);   //重新打开配置文件
          reset(tinfof);
        end;  assignfile(twritef,edit2.Text);   //打开要写入的文件
      rewrite(twritef,1);
      
      while not eof(tinfof)do     //循环读取配置文件中的信息,即文件名;
        begin
          readln(tinfof,fname);
          showmessage(path+fname);
          if fileexists(path+fname) then
            begin
              assignfile(treadf,path+fname);
              reset(treadf,1);
              while not eof(treadf) do //从文件块中读数据,如果没有到文件尾,就循环读,直到把当前文件块读完
                begin
                  blockread(treadf,buf,sizeof(buf),numr);
                  blockwrite(twritef,buf,numr,numw);
                end;
            end;
        end;
      closefile(tinfof);
      closefile(twritef);
      closefile(treadf);
      showmessage('successfully!');  end;procedure TForm1.Button2Click(Sender: TObject);
    var
      treadf,twritef:file;
      buf:array[1..2048]of char;
      numr,numw,count,co:integer;
      path,fname:string;
    begin
      path:='e:\';
      fname:='ss.mpeg';
      count:=0;
      co:=0;
      try
        assignfile(treadf,path+fname);
        reset(treadf,1);
        assignfile(twritef,'i:\a.mpeg');
        rewrite(twritef,1);
        while not eof(treadf) do    //如果没有到文件尾就一直读
          begin
            inc(count);
            blockread(treadf,buf,sizeof(buf),numr);
            if (count*2 div 1024)=10 then
              begin
                inc(co);
                closefile(twritef);      //如果文件块为用户自定义的大小时,就关闭文件,重新再生成一个文件;
                assignfile(twritef,'i:\a'+inttostr(co)+'.mpeg');
                rewrite(twritef,1);
                blockwrite(twritef,buf,numr,numw);
                count:=0;
              end
            else
              begin
                blockwrite(twritef,buf,numr,numw);
              end;
          end;
      finally
        closefile(treadf);
        closefile(twritef);
      end;
      showmessage('successfully!');  
    end;procedure TForm1.Button3Click(Sender: TObject);
    begin
      showmessage(extractfilename('i:\a.mpeg'));
    end;end.
      

  3.   

    以上是我写的一段代码,用途是把多个文件合并成一个文件,其实Delphi里面有相似的例子,你也可以看一下,