5,391
社区成员
发帖
与我相关
我的任务
分享
Function CopyFileAndDir(SourceDir,DestDir:String;nLx:Integer):Boolean;
Var
Opstruc: TSHFileOpStruct;
frombuf,tobuf: Array[0..128] of Char;
begin
FillChar(frombuf,Sizeof(frombuf),0);
FillChar(tobuf,Sizeof(tobuf),0);
StrPcopy(frombuf,SourceDir);
Case nLx of
1:
StrPcopy(tobuf,DestDir);
end;
With Opstruc Do
Begin
Wnd:=0;
Case nLx of
1: wFunc:=FO_COPY;
2: wFunc:=FO_DELETE;
Else wFunc:=FO_COPY;
end;
pFrom:=@frombuf;
pTo:=@tobuf;
fFlags:=FOF_NOCONFIRMATION;
fAnyOperationsAborted:=False;
hNameMappings:=Nil;
lpszProgressTitle:=Nil;
end;
try
ShFileOperation(OpStruc);
Result:=True;
except
Result:=False;
end;
end;
Function CopyFileAndDir(FromDir,ToDir: string):boolean;
var
T:TSHFileOpStruct; //定义文件操作结构(其实就是一个Packed记录类型)
begin
With T do
Begin
//Wnd:=Fm_Create_Question.Handle ;
Wnd:=0;
wFunc:=FO_COPY; //执行复制操作
pFrom:=Pchar(FromDir+#0#0); //加#0
pTo:=pchar(ToDir+#0#0); //加#0
hNameMappings:=nil;
lpszProgressTitle:=nil;
fFlags:=FOF_NOCONFIRMATION;
End;
if SHFileOperation(T)=0 then //文件操作函数SHFileOperation操作成功返回0
result:=True
else
result:=False;
end;