我使用以下代码获取文件和文件夹列表。我似乎无法将列表包含在隐藏文件和文件夹中。
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;
答案 0 :(得分:3)
以下是德尔福帮助的引用:
Attr参数指定除了所有普通文件之外还要包含的特殊文件。在指定Attr参数时,请从这些文件属性常量中进行选择。
您应该使用faDirectory
或faHidden
或其他标志,而不只是faDirectory
并阅读有关FindFirst
的帮助!