例如我想搜索文件夹userinfo并获取此文件夹下所有的子文件夹名,我要的是文件夹名,不是文件名。请给出示例源码。

解决方案 »

  1.   

    直接用DirectoryListBox控件搞定  DirectoryListBox1.Directory := 'C:\例子';
      ShowMessage(DirectoryListBox1.Items.Text);
      

  2.   

    example:extractfilename:获取文件名
    extractfilepath:获取文件路径
    extractfileext:获取扩展名假若有一个'pro.txt'文件
    用opendialog打开
    就写
    if opendialog1.execute then
    filename := extractfilename(opendialog1.filename);
    获得文件名
    外加:extractfilepath--获取文件路径;如:path := extracfilepath(parameter(0)) +filename 这样就得到了整个文件路径
         ExtractFileExt--获取扩展名;如:name := ExtractFileExt(filename);再自定義一個變量,將文件名存到變量中,再上傳到數據庫中
      

  3.   

    遍历的代码自己搜一下,很多sr: TSearchRec判断是否文件夹,你只需要判断sr.attr就可,faDirectory 是文件夹
      

  4.   

    var
    SearchRec:TSearchRec;
    ................. FindFirst(SearchPath+'userinfo\*.*',faAnyFile,SearchRec);
     while (FindNext(SearchRec)=0) do
         begin
           if (SearchRec.Name<>'') and (SearchRec.Attr=faDirectory)   then
              begin
                showmessage(SearchPath+SearchRec.Name);
              end;
         end;
     FindClose(SearchRec);