使用Delphi XE5时如何查看包含隐藏的所有文件和文件夹?

时间:2014-05-28 19:24:49

标签: delphi delphi-xe5 hidden-files findfirst

我使用以下代码获取文件和文件夹列表。我似乎无法将列表包含在隐藏文件和文件夹中。

procedure GetAllSubFolders(sPath: String; Listbox: TListbox);
var
  Path: String;
  Rec: TSearchRec;
begin
  try
    Path := IncludeTrailingBackslash(sPath);
    if FindFirst(Path + '*.*', faDirectory, Rec) = 0 then
    try
      repeat
        if (Rec.Name <> '.') and (Rec.Name <> '..') then
        begin
          if (ExtractFileExt(Path + Rec.Name) <> '') And (Directoryexists(Path + Rec.Name + '\') = False) then
          Begin
            Listbox.Items.Add(Path+Rec.Name);
          End;
          GetAllSubFolders(Path + Rec.Name, Listbox);
        end;
      until FindNext(Rec) <> 0;
    finally
      FindClose(Rec);
    end;
  except
    on e: Exception do
      Showmessage('Err : TForm1.GetAllSubFolders - ' + e.Message);
  end;
end;

1 个答案:

答案 0 :(得分:3)

以下是德尔福帮助的引用:

  

Attr参数指定除了所有普通文件之外还要包含的特殊文件。在指定Attr参数时,请从这些文件属性常量中进行选择。

您应该使用faDirectoryfaHidden或其他标志,而不只是faDirectory并阅读有关FindFirst的帮助!