Sign in Join

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

Mailing lists / fpc-pascal / 2026-09

FindFirst/FindNex question

7 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

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

Bart

Hi,

Just curious.

Given a situation where FindFirst/FindNext returns 0 (=succes), under which circumstance can the TSearchRec.Name become an empty string?

I'm asking because we have code in our codebase (fpc/lazarus) like:

=======
  if FindFirst(CurSrcDir+AllFilesMask,DeleteMask,FileInfo)=0 then
    Try
      repeat
        // check if special file
        if (FileInfo.Name='.') or (FileInfo.Name='..') or
(FileInfo.Name='') then
          continue;
========

Never saw that on Windows or Linux, but since fpc supports more platforms, maybe some of them may return an ampty string for TSearchRec.Name?

Bart
Alexey T.
to Bart
under which circumstance can the TSearchRec.Name become an empty string?

Only under situation of currupted file system on Unix like systems, where os trusts the empty filename. It never happens in real life. It was a defensive peogramming.

Tomas Hajny
to Bart: Just curious. Given a situation where FindFirst/FindNext returns 0 (=succes), under which…
Bart wrote 22 lines
Hi, Just curious. Given a situation where FindFirst/FindNext returns 0 (=succes), under which circumstance can the TSearchRec.Name become an empty string? I'm asking because we have code in our codebase (fpc/lazarus) like: ======= if FindFirst(CurSrcDir+AllFilesMask,DeleteMask,FileInfo)=0 then Try repeat // check if special file if (FileInfo.Name='.') or (FileInfo.Name='..') or (FileInfo.Name='') then continue; ======== Never saw that on Windows or Linux, but since fpc supports more platforms, maybe some of them may return an ampty string for TSearchRec.Name?

I don't pretend knowing behaviour of all platforms supported by FPC, but I don't think that it should happen. However, you don't show the end of the repeat until cycle - depending on the exact condition there, the check might be relevant for the repetitions (not that I'd expect it, just for completeness sake).

Tomas

Bart
to Tomas Hajny
However, you don't show the end of the repeat until cycle - depending on the exact condition there, the check might be relevant for the repetitions (not that I'd expect it, just for completeness sake).

The rest of the code is just iignored in that case:

====
      repeat
        // check if special file
        if (FileInfo.Name='.') or (FileInfo.Name='..') or
(FileInfo.Name='') then
          continue;
        //handle file or dir
      until {$IFDEF
FPC_DOTTEDUNITS}System.{$ENDIF}SysUtils.FindNext(FileInfo)0;
====
Bart
Tomas Hajny
to Bart
Bart wrote 20 lines
On Sun, Sep 13, 2026 at 7:35 PM Tomas Hajny via fpc-pascal wrote: > However, you don't show the end of > the repeat until cycle - depending on the exact condition there, the > check might be relevant for the repetitions (not that I'd expect it, > just for completeness sake). The rest of the code is just iignored in that case: ==== repeat // check if special file if (FileInfo.Name='.') or (FileInfo.Name='..') or (FileInfo.Name='') then continue; //handle file or dir until {$IFDEF FPC_DOTTEDUNITS}System.{$ENDIF}SysUtils.FindNext(FileInfo)0; ====

Indeed, then it cannot make any difference either because FindNext is checked to be 0 there as well.

Tomas

Bart
to Tomas Hajny
Indeed, then it cannot make any difference either because FindNext is checked to be 0 there as well.

Example code taken from function DeleteDirectory in systm.ioutils unit. (Possibly a copy of the same code in Lazarus, or vice versa.)

Well, it won't harm either...

Bart