荔园在线

荔园之美,在春之萌芽,在夏之绽放,在秋之收获,在冬之沉淀

[回到开始] [上一篇][下一篇]


发信人: oopilix (优雅的), 信区: Visual
标  题: [zl]to split a file in delphi
发信站: 荔园晨风BBS站 (Sun Jun  1 23:18:18 2003), 站内信件

TFileStream should work fine, everything should be straightword, just pay close
attention to details.

Obviously, you need some kind of interface (Gui, command line args, etc.) to
control the process.

This is off the top of my head, so it might need work. I don't have any error
handling either.

procedure FileSplit(nm: string; blklen: integer);
var
 bytesread: integer;
 fin: TFileStream;
 fout: TFileStream;
 buf: string;
 blkno: integer;
 outnm: string;
begin
 setlength(buf, blklen);
 fin := nil;
 blkno := 0;
 try
   fin := TFileStream.Create(nm, fmOpenRead);
   while (true) do
   begin
     bytesread := fin.read(buf[1], blklen);
     if (bytesread = 0) then break;
     fout := nil;
     try
       inc(blkno)
       outnm := ChangeFileExt(nm, '.'  + IntToStr(blkno));
       fout := TFileStream.Create(outnm,  fmCreate);
       fout.write(s[1], bytesread);
     finally
       fout.free;
     end;
   end;
 finally
 end;
end;

FileJoin, then basically works in reverse, opening the output file once,
and copying chunks from the set of input files as long as there are more
input files available.

////////////////->

Code will work but it has a memory leak if you leave this out.
I left out the fin.Free; Besure to take notice of it.


--
※ 来源:·荔园晨风BBS站 bbs.szu.edu.cn·[FROM: 61.144.235.39]


[回到开始] [上一篇][下一篇]

荔园在线首页 友情链接:深圳大学 深大招生 荔园晨风BBS S-Term软件 网络书店