Difference between revisions of "Talk:is Directory empty/de"
From Free Pascal wiki
Jump to navigationJump to search (Created page with "This part: <syntaxhighlight> FindFirst(IncludeTrailingPathDelimiter(strVerzeichnis) + '*', faAnyFile, srDatensatz); for intI := 1 to 2 do if (srDatensatz.Name = '.'...") |
m (Fixed syntax highlighting) |
||
Line 1: | Line 1: | ||
This part: | This part: | ||
− | <syntaxhighlight> | + | <syntaxhighlight lang=pascal> |
FindFirst(IncludeTrailingPathDelimiter(strVerzeichnis) + '*', faAnyFile, srDatensatz); | FindFirst(IncludeTrailingPathDelimiter(strVerzeichnis) + '*', faAnyFile, srDatensatz); | ||
Line 15: | Line 15: | ||
I would rewrite that like: | I would rewrite that like: | ||
− | <syntaxhighlight> | + | <syntaxhighlight lang=pascal> |
if FindFirst(IncludeTrailingPathDelimiter(strVerzeichnis) + '*', faAnyFile, srDatensatz) = 0 then | if FindFirst(IncludeTrailingPathDelimiter(strVerzeichnis) + '*', faAnyFile, srDatensatz) = 0 then |
Latest revision as of 07:55, 18 February 2020
This part:
FindFirst(IncludeTrailingPathDelimiter(strVerzeichnis) + '*', faAnyFile, srDatensatz);
for intI := 1 to 2 do
if (srDatensatz.Name = '.') or (srDatensatz.Name = '..') then
Result := FindNext(srDatensatz) <> 0;
seems to assume that '.' and '..' will always be the first two reported entries by FindFirst/FindNext.
This may not be the case (some filesystems do not support .. (at least that's what the fpc sources suggest)).
I would rewrite that like:
if FindFirst(IncludeTrailingPathDelimiter(strVerzeichnis) + '*', faAnyFile, srDatensatz) = 0 then
repeat
if not ((srDatensatz.Name = '.') or (srDatensatz.Name = '..')) then Result := True;
until Result or (FindNext(srDatensatz) <> 0);