如何获取一个目录下所有文件的名字?取到名字后放到文本文件或数据库中

解决方案 »

  1.   

    搜索指定目录下的文件的函数,可能对你有帮助procedure pSearchFile(mPath: TFileName);
      var
        vSearchRec: TSearchRec;
        K,i: Integer;
      begin
        K := FindFirst(mPath + '*.*', faAnyFile, vSearchRec);
        i:=i+1;
        while K = 0 do
        begin
          {if (vSearchRec.Attr and faDirectory > 0) and
            (Pos(vSearchRec.Name, '..') = 0) then
             pSearchFile(mPath + vSearchRec.Name)
          else //}
            if Pos(vSearchRec.Name, '..') = 0 then
               begin
                  form1.Memo1.Lines.Add('文件:'+vSearchRec.Name);
               end;
          K := FindNext(vSearchRec);
        end;
        FindClose(vSearchRec);
      end;
      

  2.   

    用win3.1选项卡下面的DirectoryListBox1和FileListBox1控件即可做到
    前者用来获得磁盘目录,后者可以用来取文件名称.
      

  3.   

    1、放一个listbox1及edit1及按钮
    2、按钮中写代码
    SendMessage(ListBox1.Handle, LB_DIR, DDL_HIDDEN+DDL_SYSTEM, integer(PChar('c:\*.*')));此行命令是把C盘根目录下的所有文件的文件名列到listbox1中,剩下的如何操作就很简单了更详细的参数察看API的LB_DIR帮助
      

  4.   

    Hank(星星农场) ( )
    -----------强淫,又学到了新东西.原来可以通过发送消息搞定
      

  5.   

    procedure TForm_DPNForm.InitView(Module: TDPNModule);
    var
        Node0,Node1,Nodex: TTreeNode;
        i:integer;
        strpath :  string;
        FileListBox:TFileListBox;
        iPos: Integer;
        str0, str1: string;
    begin
        FileListBox:=TFileListBox.Create(nil);
        strpath:=ExtractFilePath(Application.Exename)+'\ReportTemplate\';
        FileListBox.Parent := Self;
        FileListBox.Directory:=strpath;
        FileListBox.Mask:='*.*';
          for i:=0 to FileListBox.Items.Count-1 do
            begin
             str0:=FileListBox.Items[i];
             iPos := Pos('.', str0);
             str1 := Copy(str0, 1, iPos - 1);
             Nodex := TreeView2.Items.AddChild(Node1,str1);
             Nodex.ImageIndex := 3;
             Nodex.SelectedIndex := Node1.ImageIndex;
            end;
       FileListBox.Free;
    end;