[fpc-devel] FindFirst / FindNext gives random results in FPC 2.1.3

Michael Van Canneyt michael at freepascal.org
Mon May 14 12:25:01 CEST 2007



On Mon, 14 May 2007, Graeme Geldenhuys wrote:

> 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.

> 
> ------------------------------------------------------------
> graemeg at pluto:~/programming/tests/FilesToStringList$ 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
> 
> graemeg at pluto:~/programming/tests/FilesToStringList$ ./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
> graemeg at pluto:~/programming/tests/FilesToStringList$
> ------------------------------------------------------------
> 
> 
> 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  -  fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-devel
> 



More information about the fpc-devel mailing list