Q&A

  • listview 에 로컬 컴퓨터 탐색기구현
listview로... 로컬 컴퓨터 탐색기를 구현 하려고 합니다.

해당 디렉토리로 가면..

그 안에 있는 폴더나 파일들을 불러오고 싶은데....

불러오는 방법을 모르겠네요..

2  COMMENTS
  • Profile
    최용일 2002.09.04 02:55
    안녕하세요. 최용일입니다.

    델파이의 Demos/Virtual Listview 폴더에 보시면 아주 좋은 예제가 있습니다.

    참조하세요...

    ^^ 항상 즐코하세요...

  • Profile
    홍성락 2002.09.04 01:55
    hsr///////////////////////////////////////////////////////////
    listview로 어떻게 구현하실건가요...TreeView로 했습니다
    예전에 해당폴더의 하위파일 및 하위폴더내 모든확장자 리스트를 구해달라는 질문으로 만든 재귀호출함수로 만든것이라서 정리해서 쓰시면 될겁니다.
    unit Unit1;

    interface

    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ComCtrls, StdCtrls;

    type
      TForm1 = class(TForm)
        Button1: TButton;
        TreeView1: TTreeView;
        Edit1: TEdit;
        ListBox1: TListBox;
        procedure Button1Click(Sender: TObject);
        procedure TreeView1Click(Sender: TObject);
      private
        { Private declarations }
        procedure FileExtSearch(DirectoryList:string; Tree_Node : TTreeNode);
      public
        { Public declarations }
      end;

    var
      Form1: TForm1;

    implementation

    {$R *.dfm}

    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;

    end.