有快速搜索目录下所有文件的方法吗?(100分)

  • 主题发起人 主题发起人 delphilxh
  • 开始时间 开始时间
D

delphilxh

Unregistered / Unconfirmed
GUEST, unregistred user!
不用findfirst
 
哈哈,这个没用倒findfirst,而是FindFirstFile[:D]<br>function DoCopyDir(sDirName:String;<br>sToDirName:String):Boolean;<br>var<br>&nbsp; &nbsp;hFindFile:Cardinal;<br>&nbsp; &nbsp;t,tfile:String;<br>&nbsp; &nbsp;sCurDir:String[255];<br>&nbsp; &nbsp;FindFileData:WIN32_FIND_DATA;<br>begin<br>&nbsp; &nbsp;//先保存当前目录<br>&nbsp; &nbsp;sCurDir:=GetCurrentDir;<br>&nbsp; &nbsp;ChDir(sDirName);<br>&nbsp; &nbsp;hFindFile:=FindFirstFile('*.*',FindFileData);<br>&nbsp; &nbsp;if hFindFile&lt; &gt;INVALID_HANDLE_VALUE then<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; if not DirectoryExists(sToDirName) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ForceDirectories(sToDirName);<br>&nbsp; &nbsp; &nbsp; &nbsp; repeat<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tfile:=FindFileData.cFileName;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (tfile='.') or (tfile='..') then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Continue;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if FindFileData.dwFileAttributes=<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FILE_ATTRIBUTE_DIRECTORY then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;t:=sToDirName+'/'+tfile;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if &nbsp;not DirectoryExists(t) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ForceDirectories(t);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if sDirName[Length(sDirName)]&lt; &gt;'/' then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DoCopyDir(sDirName+'/'+tfile,t)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DoCopyDir(sDirName+tfile,sToDirName+tfile);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;t:=sToDirName+'/'+tFile;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CopyFile(PChar(tfile),PChar(t),True);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; until FindNextFile(hFindFile,FindFileData)=false;<br>&nbsp; &nbsp; &nbsp; &nbsp; FindClose(hFindFile);<br>&nbsp; &nbsp;end<br>&nbsp; &nbsp;else<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; ChDir(sCurDir);<br>&nbsp; &nbsp; &nbsp; &nbsp; result:=false;<br>&nbsp; &nbsp; &nbsp; &nbsp; exit;<br>&nbsp; &nbsp;end;<br>&nbsp; &nbsp;//回到原来的目录下<br>&nbsp; &nbsp;ChDir(sCurDir);<br>&nbsp; &nbsp;result:=true;<br>end;<br><br>
 
我的意见是自己创建个栈,然后模拟递归,应该没有比这个更快的 了
 
后退
顶部