Page 1 of 1

FindFile using *.fla;*.flac

PostPosted: March 12th, 2010, 12:08 pm
by SharkFinMike
Hi,
I've been using FindFile for some time now and it's never let me down.
However, I ran a search today with FindFile passing *.fla;*.flac to the Criteria.Files.Filename property and the search returned the same file (with a .flac extension) twice! FileFind is clearly matching .flac = .flac correctly, but also .fla = .flac - which can't be right?

Anyway, thanks for the components,

Mike

Re: FindFile using *.fla;*.flac

PostPosted: March 12th, 2010, 4:40 pm
by Kambiz
It's the way windows works.

Use this trick:

Code: Select all
FindFIle.Criteria.Files.Filename := '*.fla?';
FindFIle.Criteria.Filters.Clear;
FindFIle.Criteria.Filters.Add('>*.fla');    // include *.fla
FindFIle.Criteria.Filters.Add('>*.flac');   // include *.flac
FindFIle.Criteria.Filters.Add('*.*');       // exclude anything else

Also, you can set these settings at design time.

Re: FindFile using *.fla;*.flac

PostPosted: March 12th, 2010, 11:48 pm
by SharkFinMike
Thanks for the tip Kambiz, I'll give it a try.

Mike

Re: FindFile using *.fla;*.flac

PostPosted: March 15th, 2010, 6:41 pm
by SharkFinMike
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