FindFile using *.fla;*.flac

Please post bug reports, feature requests, or any question regarding the DELPHI AREA projects here.

FindFile using *.fla;*.flac

Postby SharkFinMike » March 12th, 2010, 12:08 pm

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
User avatar
SharkFinMike
Member
Member
 
Posts: 3
Joined: March 12th, 2010, 11:37 am

Re: FindFile using *.fla;*.flac

Postby Kambiz » March 12th, 2010, 4:40 pm

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.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Re: FindFile using *.fla;*.flac

Postby SharkFinMike » March 12th, 2010, 11:48 pm

Thanks for the tip Kambiz, I'll give it a try.

Mike
User avatar
SharkFinMike
Member
Member
 
Posts: 3
Joined: March 12th, 2010, 11:37 am

Re: FindFile using *.fla;*.flac

Postby SharkFinMike » March 15th, 2010, 6:41 pm

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
User avatar
SharkFinMike
Member
Member
 
Posts: 3
Joined: March 12th, 2010, 11:37 am


Return to DELPHI AREA Projects

Who is online

Users browsing this forum: No registered users and 1 guest

cron