procedure TForm1.Button1Click(Sender: TObject);
var
TFileInfo:TSearchRec;
hFile:HWND;
b:Boolean;
begin
hFile:=FindFirst('G:\\*.exe',faAnyFile,TFileInfo);
if hFile=0 then Memo1.Lines.Add('没打开');
Memo1.Lines.Add(TFileInfo.Name);
while hFile=0 do begin
hFile:=findnext(TFileInfo);
Memo1.Lines.Add(TFileInfo.Name);
end;
end;
function FindFirst(const Path: string; Attr: Integer;
var F: TSearchRec): Integer;
const
faSpecial = faHidden or faSysFile or faVolumeID or faDirectory;
{$IFDEF MSWINDOWS}
begin
F.ExcludeAttr := not Attr and faSpecial;
F.FindHandle := FindFirstFile(PChar(Path), F.FindData);
if F.FindHandle <> INVALID_HANDLE_VALUE then
begin
Result := FindMatchingFile(F);
if Result <> 0 then FindClose(F);
end else
Result := GetLastError;
end;
{$ENDIF}
{$IFDEF LINUX}
begin
F.ExcludeAttr := not Attr and faSpecial;
F.PathOnly := ExtractFilePath(Path);
F.Pattern := ExtractFileName(Path);
if F.PathOnly = '' then
F.PathOnly := IncludeTrailingPathDelimiter(GetCurrentDir);
F.FindHandle := opendir(PChar(F.PathOnly));
if F.FindHandle <> nil then
begin
Result := FindMatchingFile(F);
if Result <> 0 then
FindClose(F);
end
else
Result:= GetLastError;
end;
{$ENDIF}
从这里我们可以看到,在windows系统中,默认的过滤范围是
faSpecial = faHidden or faSysFile or faVolumeID or faDirectory;