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 copy multiple files into one 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
20-Oct-02
Category
Files Operation
Language
Delphi 2.x
Views
61
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

Remember DOS? We can combine multiple ASCII files to one by using the copy command 
like: copy file1 + file2 + file3 file4 .That makes file4 to become the sum of 
file1, file2 and file3. Does the ShFileOperation API supports this feature or is 
there any other API support this?

Answer:

Solve 1:
1   
2   procedure TForm1.Button1Click(Sender: TObject);
3   var
4     Stream1, Stream2: TFileStream;
5   begin
6     Stream1 := TFileStream.Create('c:\file4', fmCreate or fmShareExclusive);
7     try
8       { first file }
9       Stream2 := TFileStream.Create('c:\file1', fmOpenRead or fmShareDenyNone);
10      try
11        Stream1.CopyFrom(Stream2, Stream2.Size);
12      finally
13        Stream2.Free;
14      end;
15      { next file }
16      Stream2 := TFileStream.Create('c:\file2', fmOpenRead or fmShareDenyNone);
17      try
18        Stream1.CopyFrom(Stream2, Stream2.Size);
19      finally
20        Stream2.Free;
21      end;
22      { and so on }
23    finally
24      Stream1.Free;
25    end;
26  end;



Solve 2:
27  
28  function AppendFiles(Files: TStrings; const DestFile: string): integer;
29  var
30    srcFS, destFS: TFileStream;
31    i: integer;
32    F: string;
33  begin
34    result := 0;
35    if (Files.Count > 0) and (DestFile <> '') then
36    begin
37      destFS := TFileStream.Create(DestFile, fmCreate or fmShareExclusive);
38      try
39        i := 0;
40        while i < Files.Count do
41        begin
42          F := Files(i);
43          Inc(i);
44          if (CompareText(F, DestFile) <> 0) and (F <> '') then
45          begin
46            srcFS := TFileStream.Create(F, fmOpenRead or fmShareDenyWrite);
47            try
48              if destFS.CopyFrom(srcFS, 0) = srcFS.Size then
49                Inc(result);
50            finally
51              srcFS.Free;
52            end;
53          end
54          else
55          begin
56            { error }
57          end;
58        end;
59      finally
60        destFS.Free;
61      end;
62    end;
63  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