急求‘文件分割’的原码!谢谢

解决方案 »

  1.   

    我这里有一个,给你:var
      treadf,twritef:file;
      tinfof:textfile;
      path,fname,exfile,filename:string;
      buf:array[1..1024]of char;
      numr,numw,fco,count,blocksize:integer;
      tfm:tfilestream;
    begin
      try
        count:=0; //blockread读的次数,用以计算产生文件块的大小
        fco:=1;   //分成的块数
        
        path:=getcurrentdir()+'\';
        fname:=form1.FileListBox1.FileName;
        
        tfm:=tfilestream.Create(fname,fmopenread); //得到文件的大小
        blocksize:= tfm.Size div (1024*1024*2);
        count2:=tfm.Size div (1024*2);             //获得文件有多少个2M
        tfm.Free;    exfile:=extractfilename(fname);  //得到要分割文件名及扩展名
        filename:=getfilename(fname);   //得到分割文件名,不含扩展名    assignfile(treadf,fname); //打开要分割的文件
        reset(treadf,1);
        assignfile(twritef,path+exfile+'1');//关联要写入的文件并打开
        rewrite(twritef,1);    assignfile(tinfof,path+filename+'.lpkit');  //为写入配置文件准备
        rewrite(tinfof);
        writeln(tinfof,exfile+'1');    //向配置文件中写入第一个文件名    screen.Cursor:=crappstart;    //设置鼠标的状态
        //form1.Cursor:=crappstart;    synchronize(setv);   //设置文件的进度条    while not eof(treadf)do
          begin
            inc(count);
            blockread(treadf,buf,sizeof(buf),numr);
            if (count div 1100)>=blocksize then
              begin
                closefile(twritef); //如果文件块为用户自定义的大小时,就关闭文件,重新再生成一个文件;
                inc(fco);
                writeln(tinfof,exfile+inttostr(fco));  //向配置文件中写入文件名
                assignfile(twritef,path+exfile+inttostr(fco));  //重新生成一个新的文件块
                rewrite(twritef,1);
                blockwrite(twritef,buf,numr,numw);
                count:=0;            synchronize(setstep);//设置文件的标准步进setstep;          end
            else
              begin
                blockwrite(twritef,buf,numr,numw);
                synchronize(setstep);//设置文件的标准步进setstep;
                
              end;
          end;
        closefile(treadf);
        closefile(twritef);
        closefile(tinfof);
        screen.Cursor:=crdefault;
        //form1.Cursor:=crdefault;
        messagebox(form1.Handle,pchar('分割了:'+inttostr(fco)+'块'+#13+'请到目录:"'+path+'"下去查看!'),'提示',mb_ok or mb_iconinformation);    synchronize(setvv);       //置为初始态    shellexecute(form1.Handle,'open',pchar(path),'-s','',sw_shownormal);
      except
        try
          screen.Cursor:=crdefault;
          synchronize(setvv);
          closefile(treadf);
          closefile(twritef);
          closefile(tinfof);
        except
          messagebox(form1.Handle,pchar('读取文件出错,请重新选择要分割的文件!'),'警告',mb_ok or mb_iconwarning);
        end;
      end;
      
    end;