Hi
I am trying to recurse a given directory and hash each file found.
I have learnt that TFileSearcher is the way to go with this and, having read
http://lazarus.firmos.at/index.php?topic=11200.0 have the following code that very nicely allows the user to select the directory and the content is outputted to a memo box.
procedure TForm1.Button3Click(Sender: TObject);
var
DirToHash : string;
sl :TStringList;
begin
if SelectDirectoryDialog1.Execute then
begin
DirSelectedField.Caption := SelectDirectoryDialog1.FileName;
DirToHash := SelectDirectoryDialog1.FileName;
if DirPathExists(DirToHash) then // Check selected dir exists.
begin
sl := TStringList.Create;
try
sl := FindAllFiles(DirToHash, '*.*', True); // Finds all files and puts in list
Memo1.Lines.Assign(sl);
// SOMEHOW NEED TO HASH FILES HERE...
finally
sl.Free;
end;
end;
end;
However, because FindAllFiles outputs the finished result to s1, I can't intervene and ask it to hash each file, while it's at it. I think I need to open each file (using 'reset') to do this.
In other words, I want my output in the memo box to be both the filename and the accompanying file hash.
Also, as s1 is a string list, a need to open the actual file fo reading and hashing. MDHash can hash a file without opening it into memory, but I'm not sure how to use that in this context?
I know the syntax for hashing a single file from an OpenDialog no problem but I don't know how to interject that into the listing above. Can anyone help?
Many thanks
Ted