Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2014-12

findfirst wildcards...

25 messages · 8 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

waldo kitty

how do you process for multiple filemasks?

eg: find ts??????.sel and t???.sel for the same processing run

====== snip filemask.pas ======
Program Filemasks;
Uses
   SysUtils, StrUtils, Classes;
var
   dirSR : TSearchRec;
   flist : TStringList;
   fmask : string;
begin
   if paramstr(1)  '' then
     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;
         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+'"');
//      finally
//        if assigned(flist) then
//          freeandnil(flist);
//      end;
     end
   else
     writeln('please specify a file mask - eg: *.foo');
end.
====== snip ======

as seen above, i also attempted to use try...finally in the above but fpc always complained about the next line...

Free Pascal Compiler version 2.6.4 [2014/03/02] for i386 Copyright (c) 1993-2014 by Florian Klaempfl and others Target OS: OS/2
Compiling filemask.pas
filemask.pas(19,9) Error: Identifier not found "try" filemask.pas(19,9) Fatal: Syntax error, ";" expected but "identifier FLIST" found Fatal: Compilation aborted
Error: X:\FP\2.6.4\BIN\OS2\ppc386.exe returned an error exitcode (normal if you did not specify a source file to be compiled)

what am i missing?? i've never really used this capability before...

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.

Reply by email

Bart
to waldo kitty
waldo kitty 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()?

Bart

Reply by email

waldo kitty
to Bart
Bart wrote 8 lines
On 12/2/14, waldo kitty 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()?

in the above masks, any '*' returns too many unwanted files... after some hours of experimenting i finally figured out that using '?' works better but in some cases, it can also return unwanted files (shorter filenames) than desired...

i'm not aware of MatchesMaskList but i will hunt it down and see if it helps...

thanks! ;)

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.

Reply by email

waldo kitty
to Bart: Maybe I misunderstand the question but: Use '*' as mask for FindFirst/FindNext then use…
Bart wrote 8 lines
On 12/2/14, waldo kitty 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()?

i can't find anything that is relevant or easy to understand... everything i've found seems to be pointing to lazarus code but i don't have lazarus code available on all systems this code will be compiled on :/

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.

Reply by email

waldo kitty
to Bart: Maybe I misunderstand the question but: Use '*' as mask for FindFirst/FindNext then use…
Bart wrote 8 lines
On 12/2/14, waldo kitty 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.

Reply by email

Jonas Maebe
to waldo kitty
waldo kitty wrote 7 lines
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?

"?" means "a single arbitrary character". findfirst with "t?.txt" should not match t.txt nor t11.txt either. On the other hand, "t*.txt" means "t followed by 0 or more arbitrary characters and ending in .txt". That should/will match both t.txt and t11.txt

Jonas

Reply by email

Graeme Geldenhuys
to waldo kitty: how do you process for multiple filemasks? eg: find ts??????.sel and t???.sel for the…
waldo kitty wrote
how do you process for multiple filemasks? eg: find ts??????.sel and t???.sel for the same processing run

I don't think FindFirst and FindNext has that capability. I would use the AllMasks constant and then manually match using a simple regex that caters for all variations you need. Yes, FindNext will initially match every file, but doesn't the underlying system have to look at every file anyway to only return a specific mask?

Just for your reference, the simple masks syntax.

? matches a single character
* matches multiple characters

With regex you have MUCH greater control over how to match something. For example, here is a simple regex to match the mask you listed above. I don't know how strict you want the ??? text so I used a . (any character exect \n), but you might want to tone that down a bit.

t(?:.{3}|s.{6})\.sel

Regards,
Graeme

This email and its attachments may be confidential and are intended solely for the use of the individual to whom it is addressed. Any views or opinions are solely those of the author and do not necessarily represent those of Quality Technology Systems Ltd. If you are not the intended recipient of this email and its attachments, you must take no action based upon them, nor must you copy or show them to anyone. If you receive the message in error, please immediately delete it, destroy all copies of it and notify the sender. Internet email is not a totally secure medium and therefore Quality Technology Systems Ltd does not accept legal responsibility for the contents of this message. We have taken steps to ensure that this email and any attachments are free from viruses. However, we cannot accept any responsibility for any virus transmitted by us and recommend that you subject any incoming email to your own virus checking procedure. Registered in England No. 3208823

Reply by email

Michael Van Canneyt
to Graeme Geldenhuys
Graeme Geldenhuys wrote 8 lines
On Tue, 2 Dec 2014, waldo kitty wrote: > how do you process for multiple filemasks? > > eg: find ts??????.sel and t???.sel for the same processing run I don't think FindFirst and FindNext has that capability.

They do.

Michael.

Reply by email

Graeme Geldenhuys
to Michael Van Canneyt
Michael Van Canneyt wrote
They do.

Wow. We are never to old to learn. :-) I'll have to take a closer look at that functionality.

Regards,
Graeme

This email and its attachments may be confidential and are intended solely for the use of the individual to whom it is addressed. Any views or opinions are solely those of the author and do not necessarily represent those of Quality Technology Systems Ltd. If you are not the intended recipient of this email and its attachments, you must take no action based upon them, nor must you copy or show them to anyone. If you receive the message in error, please immediately delete it, destroy all copies of it and notify the sender. Internet email is not a totally secure medium and therefore Quality Technology Systems Ltd does not accept legal responsibility for the contents of this message. We have taken steps to ensure that this email and any attachments are free from viruses. However, we cannot accept any responsibility for any virus transmitted by us and recommend that you subject any incoming email to your own virus checking procedure. Registered in England No. 3208823

Reply by email

Tomas Hajny
to waldo kitty: can you help me understand the differences in the output of the below program? given…
waldo kitty wrote 18 lines
On 12/2/2014 5:12 PM, Bart wrote: > On 12/2/14, waldo kitty 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?

.
.

Given the fact that OS/2 appeared in your listing, I can clarify the difference. It comes from the fact that in case of FindFirst/FindNext, the interpretation of wildcards is performed by the underlying operating system whereas the routine mentioned by Bart performs this interpretation inside the Pascal code. Equally to DOS (and actually implemented that way in an attempt to make OS/2 as compatible to DOS as possible), OS/2 is somewhat more "relaxed" in interpretation of question marks at the end of the file name (i.e. before the file extension) in the sense of evaluating question marks at that position (but not elsewhere) as either 1 _or_ no character.

You get the same behaviour under DOS (either compiled with TP/BP or FPC) and also e.g. under DosEmu under Linux, etc. I believe that the MS Windows NTVDM implementation would not behave that way (i.e. I believe that the DOS window simply passes the request to MS Windows which perform the evaluation differently), but I haven't tried it.

Now regarding your original question - I don't think that you can ask the operating system to search for multiple masks at the same time (and thus the RTL does not provide such functionality directly either). Scanning through all the files as suggested by Bart is the standard solution for that. However, _if_ you have reasons to be concerned about the performance of scanning through all the files (e.g. if running over a slow network drive and having to work with directories containing _many_ files - read: thousands of files at least), it is possible to reduce the number of operating system calls and network transfers by using the OS/2 API directly and providing it with a buffer sufficient for returning information about many files at once (e.g. one hundred of them, or whatever). Obviously, your code would still need to go through all of them one by another, but it would decrease the overall time needed for processing this scan. Still, as already mentioned, this solution should not be necessary under normal conditions (and it would imply necessity of changing the implementation for other operating systems - unlike to using standard RTL functionality).

Tomas

Reply by email

waldo kitty
to Jonas Maebe: "?" means "a single arbitrary character". findfirst with "t?.txt" should not match t.txt…
Jonas Maebe wrote 12 lines
On 03 Dec 2014, at 06:05, waldo kitty wrote: > 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? "?" means "a single arbitrary character". findfirst with "t?.txt" should not match t.txt nor t11.txt either.

yes, i wrote t11.txt when i should have written t1.txt... my bad...

however on
OS/2 native
OS/2 with 4OS2 command interpreter replacement
OS/2 DOS native
OS/2 DOS with 4DOS command interpreter replacement Vista (32bit)
t?.txt returns both t.txt and t1.txt...

C:\freepascal\projects\misc>dir t?.txt

Volume in drive C is SQ004512V04
Volume Serial Number is DC02-9142

Directory of C:\freepascal\projects\misc

12/02/2014 11:31 PM 2 t.txt
12/02/2014 11:31 PM 2 t1.txt
2 File(s) 4 bytes
0 Dir(s) 51,111,350,272 bytes free

C:\freepascal\projects\misc>filemask t?.txt

looking for files that match "t?.txt"

*FindFirst only - multiple masks capable*

   ff1(t?.txt);
     t.txt
     t1.txt

*FindFirst w/ MatchesMaskList*

   ff2(t?.txt);
     t1.txt

*FindFirst w/ RegExpr - multiple masks capable*

   ff3(t?.txt);
     t.txt
     t1.txt
     t11.txt

new filemask demo program follows...

===== snip filemask.lpr =====
Program Filemask;
Uses
   SysUtils, StrUtils, Classes, Masks, RegExpr;
var
   dirSR : TSearchRec;
   flist : TStringList;
   fmask : String;
   lcnt  : Integer;
procedure ff(tstr : String);
begin
   if FindFirst(tstr,faAnyFile,dirSR) = 0 then
     begin
       repeat
         flist.Add(dirSR.Name);
       until FindNext(dirSR)  0;
       {$IFDEF FPC}
       FindClose(dirSR);
       {$ENDIF}
     end;
end;
procedure ff1(tstr : String);
var
   tcnt  : Integer = 0;
   fmcnt : Integer = 0;
begin
   fmcnt := WordCount(tstr,[';']);
   if fmcnt = 0 then
     ff(tstr)
   else
     for tcnt := 1 to fmcnt do
       begin
         ff(ExtractWord(tcnt,tstr,[';']));
       end;
end;
procedure ff2(tstr : String);
begin
   if FindFirst('*',faAnyFile,dirSR) = 0 then
     begin
       repeat
         if MatchesMaskList(dirSR.Name,tstr) then
           flist.Add(dirSR.Name);
       until FindNext(dirSR)  0;
       {$IFDEF FPC}
       FindClose(dirSR);
       {$ENDIF}
     end;
end;
procedure ffregex(tstr : String);
var
   RegexObj: TRegExpr;
begin
   RegexObj := TRegExpr.Create;
   RegexObj.Expression := tstr;
   if FindFirst('*',faAnyFile,dirSR) = 0 then
     begin
       repeat
         if RegexObj.Exec(dirSR.Name) then
           flist.Add(dirSR.Name);
       until FindNext(dirSR)  0;
       {$IFDEF FPC}
       FindClose(dirSR);
       {$ENDIF}
     end;
   RegexObj.Free;
end;
procedure ff3(tstr : String);
var
   tcnt  : Integer = 0;
   fmcnt : Integer = 0;
begin
   fmcnt := WordCount(tstr,[';']);
   if fmcnt = 0 then
     ffregex(tstr)
   else
     for tcnt := 1 to fmcnt do
       begin
         ffregex(ExtractWord(tcnt,tstr,[';']));
       end;
end;
begin
   if ParamStr(1) = '' then
     WriteLn('please specify a file mask - eg: *.foo')
   else
     begin
       fmask := ParamStr(1);
       WriteLn;
       WriteLn('looking for files that match "'+fmask+'"');
       WriteLn;
       flist := TStringList.Create;
       flist.Sorted := True;
       flist.Duplicates := dupIgnore;
       flist.CaseSensitive := False;
       try
         WriteLn('*FindFirst only - multiple masks capable*');
         WriteLn;
         WriteLn('  ff1('+fmask+');');
         ff1(fmask);
         for lcnt := 1 to flist.Count do
           WriteLn('    '+flist.Strings[lcnt-1]);
         WriteLn;
         WriteLn;
         flist.Clear;
         WriteLn('*FindFirst w/ MatchesMaskList*');
         WriteLn;
         WriteLn('  ff2('+fmask+');');
         ff2(fmask);
         for lcnt := 1 to flist.Count do
           WriteLn('    '+flist.Strings[lcnt-1]);
         WriteLn;
         WriteLn;
         flist.Clear;
         WriteLn('*FindFirst w/ RegExpr - multiple masks capable*');
         WriteLn;
         WriteLn('  ff3('+fmask+');');
         ff3(fmask);
         for lcnt := 1 to flist.Count do
           WriteLn('    '+flist.Strings[lcnt-1]);
         WriteLn;
         WriteLn;
       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.

Reply by email

waldo kitty
to Tomas Hajny: . . Given the fact that OS/2 appeared in your listing, I can clarify the difference. It…
Tomas Hajny wrote 10 lines
Given the fact that OS/2 appeared in your listing, I can clarify the difference. It comes from the fact that in case of FindFirst/FindNext, the interpretation of wildcards is performed by the underlying operating system whereas the routine mentioned by Bart performs this interpretation inside the Pascal code. Equally to DOS (and actually implemented that way in an attempt to make OS/2 as compatible to DOS as possible), OS/2 is somewhat more "relaxed" in interpretation of question marks at the end of the file name (i.e. before the file extension) in the sense of evaluating question marks at that position (but not elsewhere) as either 1 _or_ no character.

right... i see this ""everywhere"" /except/ on native linux... even DOSEMU and similar that i have tested all see '?' as "0 or 1" character... even REGEX takes that approach :)

Show quoted text 5 lines
You get the same behaviour under DOS (either compiled with TP/BP or FPC) and also e.g. under DosEmu under Linux, etc. I believe that the MS Windows NTVDM implementation would not behave that way (i.e. I believe that the DOS window simply passes the request to MS Windows which perform the evaluation differently), but I haven't tried it.

cmd and command both see '?' as "0 or 1" character...

C:\freepascal\projects\misc>command

C:\FREEPA~1\PROJECTS\MISC>ver

Microsoft Windows [Version 6.0.6002]

C:\FREEPA~1\PROJECTS\MISC>dir t?.txt
Volume in drive C is SQ004512V04
Volume Serial Number is DC02-9142

Directory of C:\FREEPA~1\projects\misc

12/02/2014 11:31 PM 2 t.txt
12/02/2014 11:31 PM 2 t1.txt
2 File(s) 4 bytes
0 Dir(s) 51,110,965,248 bytes free

C:\FREEPA~1\PROJECTS\MISC>exit

C:\FREEPA~1\projects\misc>cmd
Microsoft Windows [Version 6.0.6002]
Copyright (c) 2006 Microsoft Corporation. All rights reserved.

C:\FREEPA~1\projects\misc>dir t?.txt
Volume in drive C is SQ004512V04
Volume Serial Number is DC02-9142

Directory of C:\FREEPA~1\projects\misc

12/02/2014 11:31 PM 2 t.txt
12/02/2014 11:31 PM 2 t1.txt
2 File(s) 4 bytes
0 Dir(s) 51,111,006,208 bytes free

C:\FREEPA~1\projects\misc>exit

Now regarding your original question - I don't think that you can ask the operating system to search for multiple masks at the same time (and thus the RTL does not provide such functionality directly either).

understood...

Scanning through all the files as suggested by Bart is the standard solution for that.

i didn't realize that that would be how it was done until after i started finding and reading relevant pages... when i started looking, i found nothing for plain FPC... everything was for delphi or lazarus...

Show quoted text 7 lines
However, _if_ you have reasons to be concerned about the performance of scanning through all the files (e.g. if running over a slow network drive and having to work with directories containing _many_ files - read: thousands of files at least), it is possible to reduce the number of operating system calls and network transfers by using the OS/2 API directly and providing it with a buffer sufficient for returning information about many files at once (e.g. one hundred of them, or whatever).

the most i've had to wade through was ~40000 files but i don't think that that will be much of a problem... it wasn't a problem with my previous simplistic finding and processing methods but i've recently removed the ""artificial"" file limits i had when using arrays... now i'm loading matching filenames into stringlists and then processing from there ;)

Show quoted text 6 lines
Obviously, your code would still need to go through all of them one by another, but it would decrease the overall time needed for processing this scan. Still, as already mentioned, this solution should not be necessary under normal conditions (and it would imply necessity of changing the implementation for other operating systems - unlike to using standard RTL functionality).

yeah, i'm looking for easy and simplistic cross-platform capability if i can get it... one of my projects is targetted at OS/2, winwhatever, and linux... they're all i can compile natively for... with that and the lack of lazarus on OS/2, i think the demo program i posted in my reply to jonas shows me the yellow brick road to follow to the emerald city... the hint came from bart and/or some older messages i found where it was stated that calling findfirst multiple times was a possibility... i think that (ff1) and/or the regex one i came up with (ff3) will work best for my needs...

i do also greatly appreciate bart's initial post and the subsequent ones from others... they got me started thinking clearer when i was blind and stuck before ;)

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.

Reply by email

Ralf Quint
to waldo kitty: yes, i wrote t11.txt when i should have written t1.txt... my bad... however on OS/2 native
waldo kitty wrote 26 lines
On 12/3/2014 3:41 AM, Jonas Maebe wrote: > > On 03 Dec 2014, at 06:05, waldo kitty wrote: > >> 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? > > "?" means "a single arbitrary character". findfirst with "t?.txt" > should not > match t.txt nor t11.txt either. yes, i wrote t11.txt when i should have written t1.txt... my bad... however on OS/2 native OS/2 with 4OS2 command interpreter replacement OS/2 DOS native OS/2 DOS with 4DOS command interpreter replacement Vista (32bit) t?.txt returns both t.txt and t1.txt...

On any DOS based OS (that includes OS/2 and Windows), the "?" wildcard character will find any character, including no character at all in that position. So in your example, t?.txt will find t.txt and tx.txt but not txy.txt. It will not return any filename longer than your search mask, but return shorter filenames. This is (should be) a functionality of the underlying system calls.
On *ix based systems, the filenames are evaluated by the shell, not the OS, and your search result will be different in a lot of cases...

Ralf

---
This email has been checked for viruses by Avast antivirus software. http://www.avast.com

Reply by email

Bart
to Ralf Quint
Ralf Quint wrote 6 lines
On any DOS based OS (that includes OS/2 and Windows), the "?" wildcard character will find any character, including no character at all in that position. So in your example, t?.txt will find t.txt and tx.txt but not txy.txt. It will not return any filename longer than your search mask, but return shorter filenames. This is (should be) a functionality of the underlying system calls.

Windows.FindFirstFile however treats ? as exactly 1 character AFAIK. And is I'm not mistake this was also the case with TP in the old days.

Bart

Reply by email

Ralf Quint
to Bart
Bart wrote 11 lines
On 12/3/14, Ralf Quint wrote: > On any DOS based OS (that includes OS/2 and Windows), the "?" wildcard > character will find any character, including no character at all in that > position. So in your example, t?.txt will find t.txt and tx.txt but not > txy.txt. It will not return any filename longer than your search mask, > but return shorter filenames. This is (should be) a functionality of the > underlying system calls. Windows.FindFirstFile however treats ? as exactly 1 character AFAIK. And is I'm not mistake this was also the case with TP in the old days.

I do not have a working DOS on my Windows 8.1 laptop here right now, but as long as I can remember, the "?" as always a match for "one or none", allowing for a shorter filename as the filemask to be returned. The only exception that comes to my mind though is a the combination of "??*.txt" for example, which would return all filenames at least two characters long, A quick test in a Windows 8.1 command prompt:

Directory of C:\Users\Ralf\x

12/03/2014 12:50 PM <DIR> .
12/03/2014 12:50 PM <DIR> ..
12/03/2014 12:49 PM 3 a.txt
12/03/2014 12:49 PM 3 aa.txt
12/03/2014 12:49 PM 3 aaa.txt
12/03/2014 12:50 PM 3 b.txt
12/03/2014 12:50 PM 3 bb.txt
12/03/2014 12:50 PM 3 bbb.txt
12/03/2014 12:50 PM 3 c.txt
12/03/2014 12:50 PM 3 cc.txt
12/03/2014 12:50 PM 3 ccc.txt
9 File(s) 27 bytes
2 Dir(s) 324,408,578,048 bytes free

C:\Users\Ralf\x>dir ?.txt
Volume in drive C is TI10673200G
Volume Serial Number is 5E9D-3D3F

Directory of C:\Users\Ralf\x

12/03/2014 12:49 PM 3 a.txt
12/03/2014 12:50 PM 3 b.txt
12/03/2014 12:50 PM 3 c.txt
3 File(s) 9 bytes
0 Dir(s) 324,408,578,048 bytes free

C:\Users\Ralf\x>dir ??.txt
Volume in drive C is TI10673200G
Volume Serial Number is 5E9D-3D3F

Directory of C:\Users\Ralf\x

12/03/2014 12:49 PM 3 a.txt
12/03/2014 12:49 PM 3 aa.txt
12/03/2014 12:50 PM 3 b.txt
12/03/2014 12:50 PM 3 bb.txt
12/03/2014 12:50 PM 3 c.txt
12/03/2014 12:50 PM 3 cc.txt
6 File(s) 18 bytes
0 Dir(s) 324,408,573,952 bytes free

C:\Users\Ralf\x>

---
This email has been checked for viruses by Avast antivirus software. http://www.avast.com

Reply by email

Bart
to Ralf Quint
Ralf Quint wrote 7 lines
On 12/3/2014 12:27 PM, Bart wrote: > Windows.FindFirstFile however treats ? as exactly 1 character AFAIK. > And is I'm not mistake this was also the case with TP in the old days. > A quick test in a Windows 8.1 command prompt:

I don't dispute teh way cmd/command treats ? in dir, I merely stated that the OS function FindFirstFile des not do it like that. (And so we should not change FindFirst/FidNext behaviour.)

Bart

Reply by email

waldo kitty
to Ralf Quint: On any DOS based OS (that includes OS/2 and Windows), the "?" wildcard character will…
Ralf Quint wrote 18 lines
On 12/3/2014 8:30 AM, waldo kitty wrote: > yes, i wrote t11.txt when i should have written t1.txt... my bad... > > however on > OS/2 native > OS/2 with 4OS2 command interpreter replacement > OS/2 DOS native > OS/2 DOS with 4DOS command interpreter replacement > Vista (32bit) > t?.txt returns both t.txt and t1.txt... On any DOS based OS (that includes OS/2 and Windows), the "?" wildcard character will find any character, including no character at all in that position. So in your example, t?.txt will find t.txt and tx.txt but not txy.txt. It will not return any filename longer than your search mask, but return shorter filenames. This is (should be) a functionality of the underlying system calls. On *ix based systems, the filenames are evaluated by the shell, not the OS, and your search result will be different in a lot of cases...

yep... that's exactly been my findings... my main goal, in this case, is/was to find a way of having multiple masks... messing with MatchesMaskList showed me the difference which i was trying to figure out as it was not what was expected...

now i have three choices and don't yet know which i'll choose... most likely the plain findfirst with multiple masks one... it works and its operation is as expected from ~30 years messing with computers... the regex one will definitely stay in the stack as it offers an easy method to go both ways and that may be desirable in some cases... i just have to test it on OS/2 and see if i can compile it... i can't do that with MatchesMaskList because the unit that contains it is not available on OS/2...

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.

Reply by email

waldo kitty
to Bart: Windows.FindFirstFile however treats ? as exactly 1 character AFAIK. And is I'm not…
Bart wrote 11 lines
On 12/3/14, Ralf Quint wrote: > On any DOS based OS (that includes OS/2 and Windows), the "?" wildcard > character will find any character, including no character at all in that > position. So in your example, t?.txt will find t.txt and tx.txt but not > txy.txt. It will not return any filename longer than your search mask, > but return shorter filenames. This is (should be) a functionality of the > underlying system calls. Windows.FindFirstFile however treats ? as exactly 1 character AFAIK. And is I'm not mistake this was also the case with TP in the old days.

my command line testing shows otherwise... are you speaking of GUI related code? i'm working only with the command line... no GUI stuffs at all...

C:\freepascal\projects\misc>cmd
Microsoft Windows [Version 6.0.6002]
Copyright (c) 2006 Microsoft Corporation. All rights reserved.

C:\freepascal\projects\misc>dir t*.txt
Volume in drive C is SQ004512V04
Volume Serial Number is DC02-9142

Directory of C:\freepascal\projects\misc

12/02/2014 11:31 PM 2 t.txt
12/02/2014 11:31 PM 2 t1.txt
12/02/2014 11:31 PM 2 t11.txt
3 File(s) 6 bytes
0 Dir(s) 50,785,431,552 bytes free

C:\freepascal\projects\misc>dir t?.txt
Volume in drive C is SQ004512V04
Volume Serial Number is DC02-9142

Directory of C:\freepascal\projects\misc

12/02/2014 11:31 PM 2 t.txt
12/02/2014 11:31 PM 2 t1.txt
2 File(s) 4 bytes
0 Dir(s) 50,785,431,552 bytes free

C:\freepascal\projects\misc>command
Microsoft(R) Windows DOS
(C)Copyright Microsoft Corp 1990-2001.

C:\FREEPA~1\PROJECTS\MISC>dir t?.txt
Volume in drive C is SQ004512V04
Volume Serial Number is DC02-9142

Directory of C:\FREEPA~1\projects\misc

12/02/2014 11:31 PM 2 t.txt
12/02/2014 11:31 PM 2 t1.txt
2 File(s) 4 bytes
0 Dir(s) 50,785,423,360 bytes free

C:\FREEPA~1\PROJECTS\MISC>

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.

Reply by email

waldo kitty
to Bart: I don't dispute teh way cmd/command treats ? in dir, I merely stated that the OS function…
Bart wrote 13 lines
On 12/3/14, Ralf Quint wrote: > On 12/3/2014 12:27 PM, Bart wrote: >> Windows.FindFirstFile however treats ? as exactly 1 character AFAIK. >> And is I'm not mistake this was also the case with TP in the old days. >> > A quick test in a Windows 8.1 command prompt: I don't dispute teh way cmd/command treats ? in dir, I merely stated that the OS function FindFirstFile des not do it like that. (And so we should not change FindFirst/FidNext behaviour.)

you are confusing me, now... is not the ""OS function"" the same as what the command interpreters use?? shouldn't the results be the same? as a ~30 year veteran with computers, i surely expect them to be the same... perhaps i'm just fscking old? ;)

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.

Reply by email

Ralf Quint
to Bart: I don't dispute teh way cmd/command treats ? in dir, I merely stated that the OS function…
Bart wrote
I don't dispute teh way cmd/command treats ? in dir, I merely stated that the OS function FindFirstFile des not do it like that. (And so we should not change FindFirst/FidNext behaviour.)

Well, I have no way/time to do a more extensive test right now, but I am certain that this is the way the OS function is working ever since DOS 1.x, which was the first version of DOS I used back in late '81/early '82. And I can't recall ever to have a different behavior between the internal system call and the command line. (Well, internal system calls handling paths since DOS 2.0 allow for use of both "/" and "\" as directory delimiter, while the DOS/Windows shell commonly does not). The only time that I had to deal with a decisively different behavior is on any *ix derived OS, which since the beginning of time (as far as computers go) has handled wildcards and "FindFirst" kind of calls differently and this is the main differences in code that are necessary for a lot of cross-platform applications that I have been writing for the last +30 years...

Ralf

---
This email has been checked for viruses by Avast antivirus software. http://www.avast.com

Reply by email

Tomas Hajny
to waldo kitty: yep... that's exactly been my findings... my main goal, in this case, is/was to find a…

On Wed, December 3, 2014 23:18, waldo kitty wrote: .
.

desirable in some cases... i just have to test it on OS/2 and see if i can compile it... i can't do that with MatchesMaskList because the unit that contains it is not available on OS/2...

Which unit is it, btw? Have you tried compiling that unit for OS/2? The fact that it hasn't been included with releases for OS/2 means just that noone tested it there so far, not necessarily that it might not work there...

Tomas

Reply by email

waldo kitty
to Tomas Hajny
Tomas Hajny wrote 11 lines
On Wed, December 3, 2014 23:18, waldo kitty wrote: . . > desirable in some cases... i just have to test it on OS/2 and see if i can > compile it... i can't do that with MatchesMaskList because the unit that > contains it is not available on OS/2... Which unit is it, btw? Have you tried compiling that unit for OS/2? The fact that it hasn't been included with releases for OS/2 means just that noone tested it there so far, not necessarily that it might not work there...

MatchesMaskList and its friends are in the Lazarus MASKS unit... since lazarus is not available for OS/2, i'm not looking for it to happen... then there's the difference in the way it operates compared to what is expected...

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.

Reply by email

waldo kitty
to waldo kitty
waldo kitty wrote
MatchesMaskList and its friends are in the Lazarus MASKS unit... since lazarus is not available for OS/2, i'm not looking for it to happen... then there's the difference in the way it operates compared to what is expected...

not "the way it operates"... that should say "its output"...

"then there's the difference in its output compared to what is expected..."

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.

Reply by email

Sven Barth
to Bart: I don't dispute teh way cmd/command treats ? in dir, I merely stated that the OS function…
Bart wrote 13 lines
On 12/3/14, Ralf Quint wrote: > On 12/3/2014 12:27 PM, Bart wrote: >> Windows.FindFirstFile however treats ? as exactly 1 character AFAIK. >> And is I'm not mistake this was also the case with TP in the old days. >> > A quick test in a Windows 8.1 command prompt: I don't dispute teh way cmd/command treats ? in dir, I merely stated that the OS function FindFirstFile des not do it like that. (And so we should not change FindFirst/FidNext behaviour.)

Both "dir" and FindFirstFile use the same OS functionality. And the markers are passed down as is to the filesystem drivers (so in theory there could be different behavior depending on the type of the filesystem; anyone tried the Ext2FS driver? ;) ).

Regards,
Sven

Reply by email

Bart
to waldo kitty: you are confusing me, now... is not the ""OS function"" the same as what the command…
waldo kitty wrote 6 lines
On 12/3/2014 5:09 PM, Bart wrote: >>> Windows.FindFirstFile however treats ? as exactly 1 character AFAIK. >>> And is I'm not mistake this was also the case with TP in the old days. >>> >

Seems I was mistaken. Sorry for the confusion.
FF with mask 'x?.tst' will list bot 'x.tst' and 'xx.tst'. MatchesMask('x.tst','x?.tst') resturns False as it does in Delphi (7)...

MatchesMask however treats the mask more like on nix platform and supports things that FF/FN do not.

Bart

Reply by email