uses ShellApi;<br><br><br><br>function DoCopyDir(sDirName:String;sToDirName:String;CopyProgress:TProgressBar):Boolean;<br>var<br> hFindFile:TSearchRec;//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.FindHandle :=FindFirstFile('*.*',FindFileData);<br> if hFindFile.FindHandle <>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= 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,CopyProgress)<br> else<br> DoCopyDir(sDirName+tfile,sToDirName+tfile,CopyProgress);<br> end<br> else<br> begin<br> t:=sToDirName+'/'+tFile;<br> CopyFile(PChar(tfile),PChar(t),True);<br> //XCopyFile(tfile,t);<br> CopyProgress.Position:=CopyProgress.Position +1;<br> application.ProcessMessages;<br> end;<br> until FindNextFile(hFindFile.FindHandle ,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>//---- 1.2拷贝目录的函数:CopyDir<br><br>function CopyDir(sDirName:String;sToDirName:string;CopyProgress:TProgressBar):Boolean;<br>begin<br> if Length(sDirName)<=0 then<br> exit;<br> //拷贝...<br> pb.Min :=0;<br> Result:=DoCopyDir(sDirName,sToDirName,CopyProgress);<br>end;