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