uses shellapi,SHDocVw, filectrl,//忘了那个单元了,你看看帮助
var F :TShFileOpStruct;
CreateDir(nowpath+'\'+testname);
F.wnd:=Handle;
F.wFunc:=FO_COPY; {操作方式}
F.pFrom:=pchar(nowpath+'\modal'#0#0);
F.pTo:=pchar(nowpath+'\'+testname);
F.fFlags:=FOF_ALLOWUNDO OR FOF_RENAMEONCOLLISION; {操作选项}
if ShFileOperation(F)<>0 then
ShowMessage('文件拷贝失败!');
var F :TShFileOpStruct;
CreateDir(nowpath+'\'+testname);
F.wnd:=Handle;
F.wFunc:=FO_COPY; {操作方式}
F.pFrom:=pchar(nowpath+'\modal'#0#0);
F.pTo:=pchar(nowpath+'\'+testname);
F.fFlags:=FOF_ALLOWUNDO OR FOF_RENAMEONCOLLISION; {操作选项}
if ShFileOperation(F)<>0 then
ShowMessage('文件拷贝失败!');
var
r:TSearchRec;
li_return : integer;
begin
errorMessage := '';
if not DirectoryExists(TargetDir) then CreateDir(TargetDir);
try
if FindFirst(SourceDir+'*.*', faDirectory+faArchive, r)=0 then
repeat
if (r.Name<>'.') and (r.Name<>'..') then
if (r.Attr and faDirectory<>0) and (Recursive = 1) then
MyUtil_CopyDirectory(pchar(SourceDir+r.Name+'\'), pchar(TargetDir+r.Name+'\'), Recursive)
else
if r.Attr and faArchive<>0 then
CopyFile(PChar(SourceDir+r.Name), PChar(TargetDir+r.Name), False);
until FindNext(r)<>0;
li_return := 1;
except
on E: Exception do
begin
ErrorMessage := string(E.Message);
li_return := -1;
end;
end;
result := li_return;
end;