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 tell if two files are equal. 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
Check if two files are equal 30-Aug-04
Category
Files Operation
Language
Delphi All Versions
Views
426
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
Bramsing, Leif Steen
Reference URL:
			1   unit Unit1;
2   
3   interface
4   
5   uses
6     Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7     Dialogs, StdCtrls;
8   
9   type
10    TForm1 = class(TForm)
11      Button1: TButton;
12      procedure Button1Click(Sender: TObject);
13    private
14      { Private declarations }
15    public
16      { Public declarations }
17    end;
18  
19  var
20    Form1: TForm1;
21  
22  implementation
23  
24  {$R *.dfm}
25   //  If you want to find out of 2 files are equal, then you can use this function:
26  
27  function Are2FilesEqual(const fileName1, fileName2: string): boolean;
28  var
29    ms1, ms2: TMemoryStream;
30  begin
31    result := False;
32    ms1 := TMemoryStream.Create;
33    try
34      ms1.LoadFromFile(fileName1);
35      ms2:= TMemoryStream.Create;
36      try
37        ms2.LoadFromFile(fileName2);
38        if ms1.size = ms2.size then
39          result := CompareMem(ms1.Memory, ms2.memory, ms1.size);
40      finally
41        ms2.free;
42      end;
43    finally
44      ms1.free;
45    end
46  end;
47  
48  //And you can call it like this:
49  procedure TForm1.Button1Click(Sender: TObject);
50  var
51  bSame:boolean;
52  begin
53    bSame:=Are2FilesEqual('C:\Test1.txt','C:\test2.txt');
54    if bSame then
55    Showmessage('The files are equal')
56    else
57    Showmessage('The files are Not equal');
58  end;
59  
60  end.
61  
//enjoy ;o)

			
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