试试这个:
function DoCopyDir(sDirName:String;sToDirName:String):Boolean;
var
F: TSearchRec;
//hFindFile:Cardinal;
t,tfile:String;
sCurDir:String[255];
FindFileData:WIN32_FIND_DATA;
begin
//先保存当前目录
sCurDir:=GetCurrentDir;
ChDir(sDirName);
F.FindHandle:=FindFirstFile('*.*',FindFileData);
if F.FindHandle<>INVALID_HANDLE_VALUE then
begin
if not DirectoryExists(sToDirName) then //如果目录不存在
ForceDirectories(sToDirName); //强迫建立目录
repeat
tfile:=FindFileData.cFileName;
if (tfile='.') or (tfile='..') then
Continue; //跳过两个目录标识
if FindFileData.dwFileAttributes=FILE_ATTRIBUTE_DIRECTORY then
begin
t:=sToDirName+'/'+tfile;
if not DirectoryExists(t) then
ForceDirectories(t);
if sDirName[Length(sDirName)]<>'/' then
DoCopyDir(sDirName+'/'+tfile,t)
else
DoCopyDir(sDirName+tfile,sToDirName+tfile);
end
else
begin
t:=sToDirName+'/'+tFile;
CopyFile(PChar(tfile),PChar(t),false);
end;
until FindNextFile(F.FindHandle,FindFileData)=false;
FindClose(F);
end
else
begin
ChDir(sCurDir);
result:=false;
exit;
end;
//回到原来的目录下
ChDir(sCurDir);
result:=true;
end;
function CopyDir(sDirName:String;sToDirName:string):Boolean;
begin
if Length(sDirName)<=0 then
exit;
//拷贝...
Result:=DoCopyDir(sDirName,sToDirName);
end;