Sign in Join

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

Mailing lists / fpc-devel / 2007-05

FindFirst / FindNext gives random results in FPC 2.1.3

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

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

Graeme Geldenhuys

Hi,

I modified the example43 included with the documentation of FindFirst (see below) so it can take a patch as parameter.
I then created a few dummy test files in numerical order. Run the example43 test app and expected them to be in numerical order (Delphi behavior and FPC 2.0.5 & 2.1.1 behavior). But for some reason FPC 2.1.3 has now randomly changed the order of how it finds the files.

I'm testing on Linux (i386) with FPC 2.1.3 (r7241). Is this a bug? As I mentioned, it used to work fine on 2.0.5 and 2.1.1 and Delphi.

------------------------------------------------------------ ppc386 example43.pas
Free Pascal Compiler version 2.1.3 [2007/05/02] for i386 Copyright (c) 1993-2007 by Florian Klaempfl
Target OS: Linux for i386
Compiling example43.pas
Linking example43
35 lines compiled, 0.5 sec

./example43
/tmp/Common/Modules/AD32/001
004.swf 37
Dir : .. 4096 003.swf 37
001.swf 37
002.swf 37
005.swf 37
Dir : . 4096 Finished search. Found 7 matches

------------------------------------------------------------

Here is my modified Example43 application

-------------------[examlpe43.pas]-------------------------------
Program Example43;

{ This program demonstrates the FindFirst function }

Uses SysUtils;
Var Info : TSearchRec;
    Count : Longint;
    lPath: string;
Begin
  if Paramcount > 0 then
  begin
    lPath := ParamStr(1);
    lPath := IncludeTrailingPathDelimiter(lPath);
  end;
  Count:=0;
  If FindFirst (lPath + '*',faAnyFile and faDirectory,Info)=0 then
    begin
    Repeat
      Inc(Count);
      With Info do
        begin
        If (Attr and faDirectory) = faDirectory then
          Write('Dir : ');
        Writeln (Name:40,Size:15);
        end;
    Until FindNext(info)0;
    end;
  FindClose(Info);
  Writeln ('Finished search. Found ',Count,' matches');
End.
-------------------[end---------------------
Graeme Geldenhuys General error, hit any user to continue.

Reply by email

Michael Van Canneyt
to Graeme Geldenhuys
Graeme Geldenhuys wrote 13 lines
Hi, I modified the example43 included with the documentation of FindFirst (see below) so it can take a patch as parameter. I then created a few dummy test files in numerical order. Run the example43 test app and expected them to be in numerical order (Delphi behavior and FPC 2.0.5 & 2.1.1 behavior). But for some reason FPC 2.1.3 has now randomly changed the order of how it finds the files. I'm testing on Linux (i386) with FPC 2.1.3 (r7241). Is this a bug? As I mentioned, it used to work fine on 2.0.5 and 2.1.1 and Delphi.

No ordering is guaranteed.
Not in windows, not in Linux.
That you get them ordered is most likely because you created them in that order, and the directory entries were therefor filled 'ordered'...

Michael.

Show quoted text 73 lines
------------------------------------------------------------ ppc386 example43.pas Free Pascal Compiler version 2.1.3 [2007/05/02] for i386 Copyright (c) 1993-2007 by Florian Klaempfl Target OS: Linux for i386 Compiling example43.pas Linking example43 35 lines compiled, 0.5 sec ./example43 /tmp/Common/Modules/AD32/001 004.swf 37 Dir : .. 4096 003.swf 37 001.swf 37 002.swf 37 005.swf 37 Dir : . 4096 Finished search. Found 7 matches ------------------------------------------------------------ Here is my modified Example43 application -------------------[examlpe43.pas]------------------------------- Program Example43; { This program demonstrates the FindFirst function } Uses SysUtils; Var Info : TSearchRec; Count : Longint; lPath: string; Begin if Paramcount > 0 then begin lPath := ParamStr(1); lPath := IncludeTrailingPathDelimiter(lPath); end; Count:=0; If FindFirst (lPath + '*',faAnyFile and faDirectory,Info)=0 then begin Repeat Inc(Count); With Info do begin If (Attr and faDirectory) = faDirectory then Write('Dir : '); Writeln (Name:40,Size:15); end; Until FindNext(info)0; end; FindClose(Info); Writeln ('Finished search. Found ',Count,' matches'); End. -------------------[end--------------------- -- Graeme Geldenhuys General error, hit any user to continue. _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply by email

Graeme Geldenhuys
to Michael Van Canneyt
Michael Van Canneyt wrote
No ordering is guaranteed.

Thought so... I couldn't find any reference to the result order in the Delphi or Kylix help.

Not in windows, not in Linux. That you get them ordered is most likely because you created them in that order, and the directory entries were therefor filled 'ordered'...

What is strange is that it always gave consistent results in Delphi 7 and FPC 2.0.4, 2.0.5 and 2.1.1.

As a workaround, I store the results in a sorted TStringList and work from there... Thanks for the quick response Michael.

Graeme Geldenhuys General error, hit any user to continue.

Reply by email