//拷贝目录
function DoCopyDir(sDirName: string; sToDirName: string):Boolean;
var
hFindFile: Cardinal;
t, tfile: string;
sCurDir: string;
FindFileData: WIN32_FIND_DATA;
begin
//先保存当前目录
sCurDir := GetCurrentDir;
ChDir(sDirName);
hFindFile := FindFirstFile('*.*', FindFileData);
if hFindFile <> 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), True);
end;
until FindNextFile(hFindFile, FindFileData) = False;
FindClose(hFindFile);
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
Result := DoCopyDir(sDirName, sToDirName)
else
Result := False;
end;