Search results for 'Merge Files'. 1 post(s) found.
- 2007/09/10 How to Split and Merge Files
There are times when you need to split a large file into several smaller ones (for whatever the purpose is). The following two methods use Delphi TStream objects to break a file into several files with predefined size; and to merge those files back to the original.
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;
// 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).
Another posts included in "Delphi"
| Path shortener: c:\AB\C...DE\F.ghi (0) | 2007/09/10 |
| Reading a directory content (0) | 2007/09/10 |
| Convert a BMP to a JPG (0) | 2007/09/11 |
| Get File 'Last Modified' attribute (0) | 2007/09/10 |
| From/to the 8.3 (short) format to/from the long format (0) | 2007/09/10 |
| Delete folders recursively (0) | 2007/09/10 |
| Delete files with the ability to UNDO (0) | 2007/09/10 |
| Does my CD-ROM drive contain an audio CD? (0) | 2007/09/10 |
Trackback : Cannot send a trackbact to this post.
-
Subject different money making ideas
2010/01/28 23:32
moneyideas
-
Subject different money making ideas
2010/01/29 07:48
moneyideas
-
Subject different money making ideas
2010/01/31 16:39
moneyideas

Prev

Rss Feed