Hi Kambiz,
I've been digging around in TFindFile to work out an alternative approach to your solution. The problem I have with my application is that my list of file masks is built dynamically at run-time; so your solution - whilst fine for hard-coded masks - isn't really working for me.
I've made a couple of changes to the TFileCriteria.Matches function as follows:
Your current code is:
- Code: Select all
function TFileCriteria.Matches(const Folder, FileName: String): Boolean;
var
I: Integer;
Path: String;
Mask: PChar;
begin
Result := True;
if Filters.Count <> 0 then
begin
...
end;
end;
My changes involve passing the current mask (thisMask) to the Matches function and doing an explicit comparison between that mask and the current file's extension. Obviously, I've had to make corresponding modifications to SearchIn and IsAcceptable to get the current mask passed to Matches.
- Code: Select all
function TFileCriteria.Matches(const Folder, thisMask, FileName: String): Boolean;
var
I: Integer;
Path,Ext: String;
Mask: PChar;
begin
//Result := True;
Ext := '*'+ExtractFileExt(FileName);
Result := CompareText(thisMask,Ext) = 0;
// if not an exact match, maybe there are some refining
// criteria in the filters...
if not Result and (Filters.Count <> 0) then
begin
...
end;
end;
This is (so far) working OK for my purposes and I wonder if this minor modification could be incorporated into an "ExactMatch" option? I'm sure you could supply a better implementation than mine!
Anyhow, thanks again for a great component,
Regards,
Mike