hsr///////////////////////////////////////////////////////////
listview로 어떻게 구현하실건가요...TreeView로 했습니다
예전에 해당폴더의 하위파일 및 하위폴더내 모든확장자 리스트를 구해달라는 질문으로 만든 재귀호출함수로 만든것이라서 정리해서 쓰시면 될겁니다.
unit Unit1;
procedure TForm1.Button1Click(Sender: TObject);
var
Tree_Node : TTreeNode;
begin
TreeView1.Items.Clear;
Tree_Node := TreeView1.Items.Add(nil,'C:ZEUS');
FileExtSearch('C:ZEUS', Tree_Node);
end;
procedure TForm1.FileExtSearch(DirectoryList:string; Tree_Node : TTreeNode);
var
SearchRec: TSearchRec;
Tree_Node_ADD : TTreeNode;
begin
if FindFirst(DirectoryList + '*.*', faAnyFile , SearchRec) = 0 then begin
repeat
if (SearchRec.Attr and FaVolumeId <> FaVolumeID) then begin
if (SearchRec.Attr and FaDirectory = FaDirectory) then begin
if (SearchRec.Name <> '.')and(SearchRec.Name <> '..') then begin
Tree_Node_ADD := TreeView1.Items.AddChild(Tree_Node,SearchRec.Name);
Tree_Node.Expand(True);
TreeView1.Refresh;
FileExtSearch(DirectoryList + '' + SearchRec.Name, Tree_Node_ADD);
end;
end;
end;
until FindNext(SearchRec) <> 0;
FindClose(SearchRec);
end;
end;
procedure TForm1.TreeView1Click(Sender: TObject);
var
i : integer;
str : string;
POwner: TTreeNode;
SearchRec: TSearchRec;
begin
str := '';
if (TreeView1.Selected.Level <> 0) then begin
POwner := TreeView1.Selected;
for i := 0 to TreeView1.Selected.Level-1 do begin
str := POwner.Parent.Text + '' +str;
POwner := POwner.Parent;
end;
end;
Edit1.Text := str + TreeView1.Selected.Text;
ListBox1.Clear;
if FindFirst(Edit1.Text + '*.*', faAnyFile , SearchRec) = 0 then begin
repeat
if (SearchRec.Attr and FaVolumeId <> FaVolumeID) then begin
if (SearchRec.Attr and FaDirectory <> FaDirectory) then begin
ListBox1.Items.Add(SearchRec.Name);
end
else begin
ListBox1.Items.Add('[폴더]' + SearchRec.Name);
end;
end;
until FindNext(SearchRec) <> 0;
FindClose(SearchRec);
end;
end;
델파이의 Demos/Virtual Listview 폴더에 보시면 아주 좋은 예제가 있습니다.
참조하세요...
^^ 항상 즐코하세요...