[fpc-pascal] findfirst wildcards...

waldo kitty wkitty42 at windstream.net
Wed Dec 3 06:05:13 CET 2014


On 12/2/2014 5:12 PM, Bart wrote:
> On 12/2/14, waldo kitty <wkitty42 at windstream.net> wrote:
>>
>> how do you process for multiple filemasks?
>>
>> eg: find ts??????.sel and t???.sel for the same processing run
>
> Maybe I misunderstand the question but:
> Use '*' as mask for FindFirst/FindNext then use MatchesMaskList()?

can you help me understand the differences in the output of the below program?

given these three filenames: t.txt t1.txt t11.txt

with mask  t?.txt  why does MatchesMaskList not show t.txt and t11.txt like 
plain findfirst?

with mask  t??.txt  why does MatchesMaskList not show t.txt and t1.txt like 
plain findfirst?

am i wrong to expect the output to be the same?

is there a way to have MatchesMaskList work like plain FindFirst routine with 
the addition of handling multiple masks?

i think i'm really only wanting something like MatchesMaskList simply for 
handling multiple masks... i'm undecided on the additional restrictiveness of 
MatchesMaskList but i can see where it could be desirable in some cases...


===== snip =====
Program Filemask;

Uses
   SysUtils, StrUtils, Classes, Masks;

var
   dirSR : TSearchRec;
   flist : TStringList;
   fmask : string;

begin
   if paramstr(1) = '' then
     writeln('please specify a file mask - eg: *.foo')
   else
     begin
       fmask := paramstr(1);
       writeln('looking for files that match "'+fmask+'"');
       writeln;
       flist := TStringList.Create;
       try
         flist.Sorted := False;
         flist.Duplicates := dupIgnore;
         flist.CaseSensitive := False;
         writeln('*using FindFirst(fmask,faAnyFile,dirSR)');
         if FindFirst(fmask,faAnyFile,dirSR) = 0 then
           begin
             repeat
               flist.Add(dirSR.Name);
               writeln(PadRight(IntToStr(flist.count),6) + ' ' + 
flist.Strings[flist.count-1]);
             until FindNext(dirSR) <> 0;
             {$IFDEF FPC}
             findclose(dirSR);
             {$ENDIF}
           end;
         writeln;
         writeln(PadRight('found ' + IntToStr(flist.count),5) + ' files matching 
"'+fmask+'"');

         flist.Clear;
         writeln;

         writeln('*using FindFirst(''*'',faAnyFile,dirSR) with MatchesMaskList');
         if FindFirst('*',faAnyFile,dirSR) = 0 then
           begin
             repeat
               if MatchesMaskList(dirSR.Name,fmask) then
                 begin
                   flist.Add(dirSR.Name);
                   writeln(PadRight(IntToStr(flist.count),6) + ' ' + 
flist.Strings[flist.count-1]);
                 end;
             until FindNext(dirSR) <> 0;
             {$IFDEF FPC}
             findclose(dirSR);
             {$ENDIF}
           end;
         writeln;
         writeln(PadRight('found ' + IntToStr(flist.count),5) + ' files matching 
"'+fmask+'"');
       finally
         if assigned(flist) then
           freeandnil(flist);
       end;
     end;
end.
===== snip =====


-- 
  NOTE: No off-list assistance is given without prior approval.
        Please *keep mailing list traffic on the list* unless
        private contact is specifically requested and granted.



More information about the fpc-pascal mailing list