你可以这样做,先在 uses里面加入 ShellApi,
procedure copyfile(Ahandle: THandle; fromDir,toDir: String);
var
SHFileOpStruct: TSHFileOpStruct;
begin
with SHFileOpStruct do
begin
Wnd := AHandle;
wFunc:= FO_COPY;
pFROM:= Pchar(FromDir);
pTo:= Pchar(ToDir);
fFlags:= FOF_NOCONFIMATION or FOF_RENAMEONCOLLISION;
fAnyOperationsAborted:= false;
end;
ShFileOperation(SHFileOpStruct);
end;上面主要是用到了ShFileOperation这个API函数,具体应该看的懂了把?呵呵
procedure copyfile(Ahandle: THandle; fromDir,toDir: String);
var
SHFileOpStruct: TSHFileOpStruct;
begin
with SHFileOpStruct do
begin
Wnd := AHandle;
wFunc:= FO_COPY;
pFROM:= Pchar(FromDir);
pTo:= Pchar(ToDir);
fFlags:= FOF_NOCONFIMATION or FOF_RENAMEONCOLLISION;
fAnyOperationsAborted:= false;
end;
ShFileOperation(SHFileOpStruct);
end;上面主要是用到了ShFileOperation这个API函数,具体应该看的懂了把?呵呵
procedure copyfile(Ahandle: THandle; fromDir,toDir: String);
var
SHFileOpStruct: TSHFileOpStruct;
begin
GetMem(FromDir, Length(AFromDirectory)+2);
try
GetMem(ToDir, Length(AToDirectory)+2);
try FillChar(FromDir^, Length(AFromDirectory)+2, 0);
FillChar(ToDir^, Length(AToDirectory)+2, 0); StrCopy(FromDir, PChar(AFromDirectory));
StrCopy(ToDir, PChar(AToDirectory)); with SHFileOpStruct do
begin
Wnd := AHandle; // Assign the window handle
wFunc := FO_COPY; // Specify a file copy
pFrom := FromDir;
pTo := ToDir;
fFlags := FOF_NOCONFIRMATION;
fAnyOperationsAborted := True;
hNameMappings := nil;
lpszProgressTitle := nil;
if SHFileOperation(SHFileOpStruct) <> 0 then
RaiseLastWin32Error;
end;
finally
FreeMem(ToDir, Length(AToDirectory)+2);
end;
finally
FreeMem(FromDir, Length(AFromDirectory)+2);
end;
end;