【问题标题】:How to see all files and folders including hidden when using Delphi XE5?使用 Delphi XE5 时如何查看所有文件和文件夹,包括隐藏的?
【发布时间】:2014-05-28 19:24:49
【问题描述】:

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

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;

【问题讨论】:

  • 查看FindFirst 函数参考,特别是Attr 参数说明。你一定会在那里找到答案……
  • 可以使用IOUtils的功能
  • @TLama 非常好。没想到要看“findfirst”部分。改成 if FindFirst(Path + '.', faAnyFile, Rec) 问题就解决了

标签: delphi delphi-xe5 hidden-files findfirst


【解决方案1】:

这是来自 Delphi 帮助的引述:

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

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

【讨论】:

    猜你喜欢
    • 2011-10-12
    • 2018-05-30
    • 2014-01-21
    • 2013-02-02
    • 2021-12-22
    • 1970-01-01
    • 1970-01-01
    • 2014-12-13
    • 1970-01-01
    相关资源
    最近更新 更多