How to use Windows API to copy files
function FileOperation(WndHandle: HWND; const SourceFile, TargetFile: string;
Action: Word): Boolean;
{
SHFileOperation is the Windows API function for doing standard file
operations, such as copying and deleting files.
WndHandle can be Application.Handle, the Form's handle or the result of
GetDeskTopWindow.
Action can be any of the following:
FO_COPY Copies the files specified by pFrom to the location specified by pTo.
FO_DELETE Deletes the files specified by SourceFile (TargetFile is ignored).
FO_MOVE Moves the files specified by SourceFile to the location specified
by TargetFile.
FO_RENAME Renames the files specified by SourceFile.
}
var
Info: TSHFileOpStruct;
Aborted : Bool;
begin
Aborted := False;
with Info do
begin
Wnd := WndHandle;
wFunc := Action;
pFrom := pChar(SourceFile);
pTo := pChar(TargetFile);
fFlags := FOF_SILENT or FOF_NOCONFIRMATION;
fAnyOperationsAborted := Aborted;
end;
try
SHFileOperation(Info);
finally
Result := not Aborted;
end;
end;