通过WinApi函数SHFileOperation可以实现
var
opstruc:TSHFileOpStruct;
FromBuf,ToBuf:array [0...128] of char
begin
fillchar(FromBuf,Sizeof(FromBuf),0);
Fillchar(ToBuf, sizeof(ToBuf),0);
StrCopy(fromBuf,PChar(edit1.text));
StrCopy(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
ShowMessage('OK');
end;