Here is a dirty but simple solution.
Drop a TFindFile and a TMemo on the form, fill the FindFile properties, and use the following code for the event handlers.
I don't describe the code because for sure you can figure it out.
- Code: Select all
var
Extensions: TStringList;
procedure TForm1.FindFile1SearchBegin(Sender: TObject);
begin
Extensions := TStringList.Create();
Extensions.CaseSensitive := True; // for search optimization, we manage case by ourselvs
Extensions.Duplicates := dupAccept; // for insert optimization, we don't have duplicates
Extensions.Sorted := True; // for search optimization, using binary search
end;
procedure TForm1.FindFile1FileMatch(Sender: TObject; const Folder: String;
const FileInfo: TSearchRec);
var
Ext: String;
Idx: Integer;
begin
Ext := LowerCase(ExtractFileExt(FileInfo.Name));
with Extensions do
begin
Idx := IndexOf(Ext);
if Idx < 0 then
AddObject(Ext, TObject(1)) // adds first occurrence
else
Objects[Idx] := TObject(Integer(Objects[Idx]) + 1); // increment occurrences
end;
end;
procedure TForm1.FindFile1SearchFinish(Sender: TObject);
var
I: Integer;
begin
// here we are going to show the search result inside a memo
for I := 0 to Extensions.Count - 1 do
Memo1.Lines.Add(Format('%s = %d', [Extensions[I], Integer(Extensions.Objects[I])]));
Extensions.Free; // we do not need the extension list anymore
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FindFile1.Execute
end;