procedure TForm12.PopulateTreeView(const Path: string; ParentNode: TTreeNode);
var
NewNode: TTreeNode;
begin
//先取所有入口
var Entries := TDirectory.GetFileSystemEntries(Path);
for var Entry in Entries do
begin
var EntryName := TPath.GetFileName(Entry);
if ParentNode = nil then
NewNode := TreeView1.Items.Add(nil, EntryName)
else
NewNode := TreeView1.Items.AddChild(ParentNode, EntryName);
if TDirectory.Exists(Entry) then //判断是否为路径(文件夹)
begin
NewNode.ImageIndex := 1; // 文件夹图标索引
NewNode.SelectedIndex := 1;
PopulateTreeView(Entry, NewNode);//是文件夹则枚举这个文件夹
end
else
begin
NewNode.ImageIndex := 0; // 文件图标索引
NewNode.SelectedIndex := 0;
end;
end;
end;