Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to split and join a file using TFileStream Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
30-Aug-02
Category
Files Operation
Language
Delphi 2.x
Views
60
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

How to split and join a file using TFileStream

Answer:
1   
2   {Procedure Splitfile
3   Parameters:
4   sourcefilename: name of file to split
5   blocksize: maximum size of the parts to create
6   
7   Call method:
8   static
9   
10  Description:
11  
12  Will split the passed file into partial files with a size of blocksize bytes (the 
13  last one may be smaller). The names of the files are created from the 
14  sourcefilename by replacing the extension with a number, .000, .001 etc. The files 
15  can be concatenated using the DOS Copy command with the /b switch to regenerate the 
16  original file.
17  
18  Error Conditions:
19  I/O errors will raise exceptions.
20  
21  Created: 03.03.98 by P. Below}
22  
23  procedure Splitfile(const sourcefilename: string; blocksize: Longint);
24  var
25    targetfilename: string;
26    filecounter: Integer;
27    bytesRemaining, bytesToWrite: LongInt;
28    source, target: TFileStream;
29  begin
30    if not FileExists(sourcefilename) or (blocksize < = 0) then
31      Exit;
32    source := TFileStream.Create(sourcefilename, fmOpenRead or fmShareDenyNone);
33    try
34      filecounter := 0;
35      bytesRemaining := source.Size;
36      while bytesRemaining > 0 do
37      begin
38        targetfilename := ChangeFileExt(sourcefilename, Format('.%.3d', 
39  [filecounter]));
40        if blocksize < bytesRemaining then
41          bytesToWrite := blocksize
42        else
43          bytesToWrite := bytesRemaining;
44        target := TFileStream.Create(targetfilename, fmCreate);
45        try
46          target.CopyFrom(source, bytesToWrite);
47          bytesRemaining := bytesRemaining - bytesToWrite;
48          Inc(filecounter);
49        finally
50          target.Free;
51        end;
52      end;
53    finally
54      source.Free;
55    end;
56  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC