文件分割合并
procedure SplitFile(FileName : TFileName; FilesByteSize : Integer) ;
// FileName == file to split into several smaller files
// FilesByteSize == the size of files in bytes
var
fs, ss: TFileStream;
cnt : integer;
SplitName: String;
begin
fs := TFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite) ;
try
for cnt := 1 to Trunc(fs.Size / FilesByteSize) + 1 do
begin
SplitName := ChangeFileExt(FileName, Format('%s%d', ['._',cnt])) ;
ss := TFileStream.Create(SplitName, fmCreate or fmShareExclusive) ;
try
if fs.Size - fs.Position < FilesByteSize then
FilesByteSize := fs.Size - fs.Position;
ss.CopyFrom(fs, FilesByteSize) ;
finally
ss.Free;
end;
end;
finally
fs.Free;
end;
end;
Note: a 3 KB file 'myfile.ext' will be split into 'myfile._1', 'myfile._2','myfile._3' if FilesByteSize parameter equals 1024 (1 KB).
procedure MergeFiles(FirstSplitFileName, OutFileName : TFileName) ;
// FirstSplitFileName == the name of the first piece of the split file
// OutFileName == the name of the resulting merged file
var
fs, ss: TFileStream;
cnt: integer;
begin
cnt := 1;
fs := TFileStream.Create(OutFileName, fmCreate or fmShareExclusive) ;
try
while FileExists(FirstSplitFileName) do
begin
ss := TFileStream.Create(FirstSplitFileName, fmOpenRead or fmShareDenyWrite) ;
try
fs.CopyFrom(ss, 0) ;
finally
ss.Free;
end;
Inc(cnt) ;
FirstSplitFileName := ChangeFileExt(FirstSplitFileName, Format('%s%d', ['._',cnt])) ;
end;
finally
fs.Free;
end;
end;
Usage:
SplitFile('c:\mypicture.bmp', 1024) ; //into 1 KB files
...
MergeFiles('c:\mypicture._1','c:\mymergedpicture.bmp') ;
http://www.cnblogs.com/hnxxcxg/archive/2012/11/04/2753259.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
2012-03-02 使用CRichEditCtrl与正则实现XML高亮编辑器
2012-03-02 两种方法查看MFC源代码
2012-03-02 LLVM CodeExtractor