怎样获取特定目录下所有的 子文件夹列表?然后获取某一个文件夹下所有的文件的文件名,不包括扩展名,但要按扩展名分类。。! 在线送分:-)提供程序者送100分!(1

H

HaiGxj

Unregistered / Unconfirmed
GUEST, unregistred user!
怎样获取特定目录下所有的 子文件夹列表?然后获取某一个文件夹下所有的文件的文件名,不包括扩展名,但要按扩展名分类。。! 在线送分:-)提供程序者送100分!(100分)<br />:-)
 
一段不知道从那抄来的函数,看看对你有没有帮助<br>/////////////////////////////////////////////////////////////////<br>//<br>// &nbsp;查询主体函数<br>// &nbsp;Mainpath: 指定的查询目录。<br>// &nbsp;Filename: 欲查询的文件。<br>// &nbsp;Foundresult: 返回的含完整路径的匹配文件(可能有多个)。<br>// &nbsp;如果有匹配文件,函数返回True,否则,返回False;<br>/////////////////////////////////////////////////////////////////<br>function SearchFile(mainpath:string;filename:string;var foundresult:TStringList):Boolean;<br>var<br>&nbsp; i:integer;<br>&nbsp; Found:Boolean;<br>&nbsp; subdir1:TStrings;<br>&nbsp; searchRec:TsearchRec;<br>begin<br>&nbsp; found:=false;<br>&nbsp; if Trim(filename)&lt;&gt;'' then<br>&nbsp; begin<br>&nbsp; subdir1:=TStringList.Create;//字符串列表必须动态生成<br>&nbsp; //找出所有下级子目录。<br>&nbsp; if (FindFirst(mainpath+'*.*', faDirectory, SearchRec)=0) then<br>&nbsp; begin<br>&nbsp; if IsValidDir(SearchRec) then<br>&nbsp; subdir1.Add(SearchRec.Name);<br>&nbsp; while (FindNext(SearchRec) = 0) do<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; if IsValidDir(SearchRec) then<br>&nbsp; &nbsp; &nbsp; &nbsp; subdir1.Add(SearchRec.Name);<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; end;<br>&nbsp; FindClose(SearchRec);<br>&nbsp; //查找当前目录。<br>&nbsp; if FileExists(mainpath+filename) then<br>&nbsp; begin<br>&nbsp; &nbsp; &nbsp;if (FindFirst(mainpath+filename, faAnyFile, SearchRec)=0) then<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; while (FindNext(SearchRec) = 0) do<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; foundresult.Add(mainpath+SearchRec.Name);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; found:=true;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; FindClose(SearchRec);<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; end;<br>&nbsp; //这是递归部分,查找各子目录。<br>&nbsp; for i:=0 to subdir1.Count-1 do<br>&nbsp; found:=Searchfile(mainpath+subdir1.Strings+'/',Filename,foundresult)or found;<br>&nbsp; //资源释放并返回结果。<br>&nbsp; subdir1.Free;<br>&nbsp; end;<br>&nbsp; result:=found;<br>end;
 
这是搜索?
 
自己用FindFirst....为一组函数搜索目录下的所有文件。<br>把文件名和扩展名分解开,放入数组中。<br>最后排一下序显示出来。
 
谢谢。。烦请各位大侠继续不吝赐教~~
 
用控件findfile,如果我更好的方法,我也关注一下
 
呵呵 &nbsp;请各位大侠继续关注,,可能大家都会碰到这样的问题啊:-) up!
 
var<br>&nbsp; pResult: LongInt;<br>&nbsp;mLstFile :tstringlist; &nbsp;<br>begin<br>&nbsp;mLstFile := tstringlist.Create; &nbsp; <br>&nbsp;pResult := FindFirst(pShareDir + '*.*', faAnyFile, pSearchRec);<br>&nbsp; &nbsp; while pResult = 0 do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; mLstFile.Add(pSearchRec.name);<br>&nbsp; &nbsp; &nbsp; pResult := FindNext(pSearchRec);<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; findclose(pSearchRec);<br>end;<br>
 
我也要用这个东东了.<br>谢谢大家.我去看看有没有更好的办法
 
呵呵 好想还差那么一些啊;; 继续努力啊 up
 
哈哈,分给我,我就给你全部源码!
 
好啊 。。只要你给源代码!! 我就给,骗你不是人!
 
to : lah998<br><br>在线等待中。。。。ing:)
 
我也要分,全要,肯定好好使,我已经用在一个压缩DLL中<br>//向指定StringList中添加指定目录下的全部子目录<br>function ListDirs(Path: string; List: TStringList): Integer;<br>var<br>&nbsp; FindData: TWin32FindData;<br>&nbsp; FindHandle: THandle;<br>&nbsp; FileName: string;<br>&nbsp; AddToList: Boolean;<br>&nbsp; TempPath : string;<br>begin<br>&nbsp; Result := 0;<br><br>&nbsp; AddToList := Assigned(List);<br><br>&nbsp; if Path[Length(Path)] &lt;&gt; '/' then<br>&nbsp; &nbsp; Path := Path + '/';<br>&nbsp; TempPath := Path ;<br>&nbsp; Path := Path + '*.*';<br><br>&nbsp; FindHandle := Windows.FindFirstFile(PChar(Path), FindData);<br><br>&nbsp; while FindHandle &lt;&gt; INVALID_HANDLE_VALUE do<br>&nbsp; begin<br>&nbsp; &nbsp; FileName := StrPas(FindData.cFileName);<br>&nbsp; &nbsp; if (FileName &lt;&gt; '.') and (FileName &lt;&gt; '..') and<br>&nbsp; &nbsp; &nbsp; ((FindData.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) &lt;&gt; 0) then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Result := Result + 1 + ListDirs(TempPath+FileName,List);<br>&nbsp; &nbsp; &nbsp; if AddToList then<br>&nbsp; &nbsp; &nbsp; &nbsp; List.Add(TempPath+FileName);<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; if not Windows.FindNextFile(FindHandle, FindData) then<br>&nbsp; &nbsp; &nbsp; FindHandle := INVALID_HANDLE_VALUE;<br>&nbsp; end;<br>&nbsp; Windows.FindClose(FindHandle);<br>end;<br>
 
请自己改一下<br>//向List中添加指定目录 &nbsp;Path 下的所有文件<br>function ListFiles(Path: string; List: TStringList): Integer;<br>var<br>&nbsp; DirInfo: TSearchRec;<br>&nbsp; r : Integer;<br>begin<br>&nbsp; Result := 0 ;<br>&nbsp; if Path[Length(Path)] &lt;&gt; '/' then<br>&nbsp; &nbsp; Path := Path + '/';<br>&nbsp; r := FindFirst(Path+'*.*', FaAnyfile, DirInfo);<br>&nbsp; while r = 0 do<br>&nbsp; begin<br>&nbsp; &nbsp; if ((DirInfo.Attr and FaDirectory &lt;&gt; FaDirectory) and<br>&nbsp; &nbsp; &nbsp; &nbsp;(DirInfo.Attr and FaVolumeId &lt;&gt; FaVolumeID)) then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; List.Add(Path+ DirInfo.Name);<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; r := FindNext(DirInfo);<br>&nbsp; end;<br>&nbsp; SysUtils.FindClose(DirInfo);<br>end;<br>
 
to newfat:<br>&nbsp; 你的源码我看了,我先试一试,但是,你还没有给出答完。。: <br>然后获取某一个文件夹下所有的文件的文件名,不包括扩展名,但要按扩展名分类。。!<br>&nbsp;xiaoxian 和 only you 给出了后面的问题的思路,如果你给出同样的更好使用的源码,<br>注意,我要按扩展名分类:你可以用 &nbsp;.txt 给一个。。如果给出了,这个100 分全给你,<br>&nbsp;我另外给 他们加分!!ok?
 
procedure TF_PhotoIE.SearchPhotoFile(Path: string; FilesList: TStringList; Recurce: boolean);<br>var<br>&nbsp; SR: TSearchRec;<br><br>begin<br>&nbsp; if Path[Length(Path)] &lt;&gt; '/' then Path := Path + '/';<br><br>&nbsp; if FindFirst(Path + '*.*', faDirectory, SR) = 0 then<br>&nbsp; begin<br>&nbsp; &nbsp; while FindNext(SR) = 0 do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; if (SR.Attr and faDirectory) = SR.Attr then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; if Recurce then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (SR.Name &lt;&gt; '.') and (SR.Name &lt;&gt; '..') then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SearchPhotoFile(Path + SR.Name, FilesList, Recurce)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FilesList.Add(Path + SR.Name);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; FindClose(SR);<br>&nbsp; end;<br>end;
 
如果是想学习建议看看Delphi得 FindNext 等函数的帮助,里面的例子<br>你要的基本上都有了
 
不好意思,网不通,让各位大富翁久等了~~
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
顶部