我正在尝试在 delphi 中检索目录的子目录,我正在使用此功能:
procedure GetSubDirectories(const directory : string; list : TStrings) ;
var
sr : TSearchRec;
begin
try
if FindFirst(IncludeTrailingPathDelimiter(directory) + '*.*', faDirectory, sr) < 0 then
Exit
else
repeat
if ((sr.Attr and faDirectory <> 0) AND (sr.Name <> '.') AND (sr.Name <> '..')) then
List.Add(IncludeTrailingPathDelimiter(directory) + sr.Name) ;
until FindNext(sr) <> 0;
finally
SysUtils.FindClose(sr) ;
end;
end;
然后我尝试了类似的东西:
procedure TForm1.FormCreate(Sender: TObject);
var
folders: TStringList;
begin
folders := TStringList.Create;
try
GetSubDirectories('c:\', folders);
ShowMessage(folders.ValueFromIndex[0]);
finally
FreeAndNil(folders);
end;
end;
消息框中显示的字符串例如:“:\Program Files”。我尝试List.Add
在 GetSubDirectories 过程中添加一个断点,然后 var 看起来像“C:\Program Files”。
为什么在消息框中删除了驱动器号?