I pass the parameter value '*1.dat'
to FindFirst, still the first file that the FindFirst() routine return is 46checks5.dat
, very consistently.
Is this a known problem?
vpath:=trim(vpath);
result:=true;
try
res:=findfirst(vpath+'\'+vmask,faarchive,search); //vmask = *1.dat
try
while res=0 do
begin
vlist.add(search.name); //searchname returned is 46checks5.dat!!!
res:=findnext(search);
end;
finally
findclose(search);
end;
except
result:=false;
end;
The reason is that the file has a "long" name, i.e. with more than 8 characters. For such files Windows also creates "short" names, that usually are created in the form
longna~1.dat
and this short name is found via*1.dat
wildcard.You can easily reproduce the same behaviour in command prompt in an empty directory:
The documentation for
FindFirstFile()
, which is the underlying API forFindFirst
states:To workaround this issue, then, rather than using Delphi's wrapper to
FindFirstFile()
, call the Win32 APIFindFirstFileEx()
. PassFindExInfoBasic
to thefInfoLevelId
parameter.