Problem with SysUtils.FindFirst/FindNext
Original Reporter info from Mantis: Rumcajs47
-
Reporter name:
Original Reporter info from Mantis: Rumcajs47
- Reporter name:
Description:
I have write a procedure called : GetDirFileList
procedure GetDirFileList(Path, Mask : string; FileList : TStrings);
var
SR: SysUtils.TSearchRec;
begin
Path := IncludeTrailingPathDelimiter(Path);
try
if SysUtils.FindFirst(Path + Mask, faAnyFile, SR) = 0 then begin
repeat
if (SR.Attr <> faDirectory) and (SR.Name <> '.') and (SR.Name <> '..') then
FileList.Add(SR.Name);
until SysUtils.FindNext(SR) <> 0;
end;
finally
SysUtils.FindClose(SR);
end;
end;
now lets say we have a Directory with this 4 files :
a.odt
b.odt
c.odt
.~lock.c.odt#
i call it like GetDirFileList('TheDirectory', '.odt', FileList)
in the FileList i expect 3 items but i got 4, the find routine finds the ".odt#" to
i mean ".odt" means for me it can be anything in front of the "." but the extension must be exactly ".odt"
This looks like a BUG to me, and its pretty danger to, you can delete someting you want if you trust FindFirst/FindNext
if this is not a bug, then how i can search exactly for ".odt" ?
Steps to reproduce:
make 4 files in a directory :
a.odt
b.odt
c.odt
.~lock.c.odt#
use the GetDirFileList routine to search for "*.odt" in this directory
Mantis conversion info:
- Mantis ID: 35742
- OS: Windows
- OS Build: 10
- Platform: Lazarus 2.0.2 x64
- Version: 3.0.4
- Fixed in revision: 42286 (#c914655a)