Performs a copy, move, rename, or delete operation on a file system object.
WINSHELLAPI int WINAPI SHFileOperation(LPSHFILEOPSTRUCT lpFileOp);
Parameters
lpFileOp:Pointer to an SHFILEOPSTRUCT structure that contains information the function needs to carry out the operation.
Return Values
Returns zero if successful or nonzero if an error occurs.
procedure TForm1.CopyBtnClick(Sender: TObject);
var
opstruc:tshfileopstruct;
frombuf,tobuf:array[0.128]of char;
begin
fillchar(frombuf,sizeof(frombuf),0);
fillchar(tobuf,sizeof(tobuf),0);
strpcopy(frombuf,pchar(edit1.Text));//源目录
strpcopy(tobuf,pchar(edit2.Text));//目的目录
//填充opstruc记录
with opstruc do
begin
wnd:=handle;
wfunc:=fo_copy;
pfrom:=@frombuf;
pto:=@tobuf;
fflags:=fof_noconfirmation or fof_renameoncollision;
fanyoperationsaborted:=false;
hnamemappings:=nil;
lpszprogresstitle:=nil;
end;
//开始复制
if shfileoperation(opstruc)=0 then
messagebox(handle,'复制完毕.','复制信息',mb_ok+mb_iconinformation);