兩個檔案的比對 |
尚未結案
|
chead
一般會員 發表:10 回覆:12 積分:4 註冊:2004-08-03 發送簡訊給我 |
|
T.J.K
中階會員 發表:3 回覆:35 積分:57 註冊:2005-06-28 發送簡訊給我 |
剛好有小朋友有類似的問題,供你參考 unit Unit1; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls; type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
aList: TStringList;
bList: TStringList;
function fFileSize(var FilePath: String) : LongWord;
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.dfm} function TForm1.fFileSize(var FilePath: String):LongWord ; //取File Size
var
FBuf: LongWord;
F: file of Byte;
begin
Result := 0;
if not FileExists(FilePath) then
begin
ShowMessage('找不到檔案【' FilePath '】');
Exit;
end;
AssignFile(F, FilePath);
Try
Reset(F);
Result := FileSize(F);
finally
CloseFile(F);
end;
end; procedure TForm1.Button1Click(Sender: TObject);
var
aSize, bSize, cSize: LongWord;
aList, bList, cList: TStringList;
i : integer;
aPath, bPath : String;
begin
cList := TStringList.Create;
aPath := 'D:\a.Txt';
bPath := 'D:\b.Txt';
aSize := fFileSize(aPath);
bSize := fFileSize(bPath); aList := TStringList.Create;
aList.LoadFromFile(aPath);
bList := TStringList.Create;
bList.LoadFromFile(bPath); if aList.Count = bList.Count then
begin
cList := aList;
Memo1.Lines[0]:= aPath ' = ' bPath ' 檔案大小。';
end
else
if aList.Count > bList.Count then
begin
cList := aList;
Memo1.Lines[0]:= aPath ' > ' bPath ' 檔案大小。';
end
else
if aList.Count < bList.Count then
begin
cList := bList;
Memo1.Lines[0]:= aPath ' < ' bPath ' 檔案大小。';
end;
Memo1.Lines.Add(''); if cList.Count > -1 then
for i := 0 to cList.Count -1 do
if (aList.Count >= i 1) and (bList.Count >= i 1) then
begin
if aList.Strings[i] <> bList.Strings[i] then
begin
Memo1.Lines.Add('第' IntToStr(i 1) '錯誤資料:');
Memo1.Lines.Add(' ' aPath ':' aList.Strings[i]);
Memo1.Lines.Add(' ' bPath ':' bList.Strings[i]);
Memo1.Lines.Add('');
end;
end
else begin
if (bList.Count < i) then
begin
Memo1.Lines.Add('第' IntToStr(i 1) '錯誤資料:');
Memo1.Lines.Add(' ' aPath ':' aList.Strings[i]);
Memo1.Lines.Add(' ' bPath ':');
Memo1.Lines.Add('');
end;
if (aList.Count < i) then
begin
Memo1.Lines.Add('第' IntToStr(i 1) '錯誤資料:');
Memo1.Lines.Add(' ' aPath ':');
Memo1.Lines.Add(' ' bPath ':' bList.Strings[i]);
Memo1.Lines.Add('');
end;
end;
end; end.
|
chead
一般會員 發表:10 回覆:12 積分:4 註冊:2004-08-03 發送簡訊給我 |
|
chead
一般會員 發表:10 回覆:12 積分:4 註冊:2004-08-03 發送簡訊給我 |
|
T.J.K
中階會員 發表:3 回覆:35 積分:57 註冊:2005-06-28 發送簡訊給我 |
unit Unit1; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls; type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
FBuf: PByte;
FBufSize: LongWord;
function ReadFile(var FileName: String): Boolean;
{ Private declarations }
public
{ Public declarations }
end; type
FileInfo = packed record
aBuf: PByte;
aBufSize: LongWord;
bBuf: PByte;
bBufSize: LongWord;
end;
var
Form1: TForm1; implementation {$R *.dfm} function TForm1.ReadFile(var FileName: String): Boolean;
var
F: file of Byte;
fSize: LongWord;
I: LongWord;
begin
Result := False;
if not FileExists(FileName) then
Exit; if Assigned(FBuf) then
begin
FreeMem(FBuf);
FBuf := nil;
end; AssignFile(F, FileName);
try
Reset(F);
fSize := FileSize(F);
FBufSize := fSize;
GetMem(FBuf, FBufSize); BlockRead(F, FBuf^, FBufSize, I);
if FBufSize <> I then
showmessage('無法開始檔案。');
finally
CloseFile(F);
end;
Result := True;
end; procedure TForm1.Button1Click(Sender: TObject);
var
aFN, bFN: String;
FNInfo: FileInfo;
p: PByte;
i : integer;
begin
aFN := 'D:\a.Doc';
bFN := 'D:\b.Doc'; if ReadFile(aFN) then
begin
FNInfo.aBuf := FBuf;
FNInfo.aBufSize := FBufSize;
end
else Exit; if ReadFile(bFN) then
begin
FNInfo.bBuf := FBuf;
FNInfo.bBufSize := FBufSize;
end
else Exit;
end; end. 以上供你參考,希望對你有幫助
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |