function TFmMain.CopyDir(sDirName: string; sToDirName: string): Boolean;
begin
if Length(sDirName) <= 0 then
exit;
Result := SelfCopyDir(sDirName, sToDirName);
end;
function TFmMain.SelfCopyDir(sDirName: string; sToDirName: string): Boolean;
var
F : TSearchRec;
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
CopyDir(sDirName + '\' + tfile, t)
else
CopyDir(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;