picture

Copy Directory in Delphi.

In order to copy the content of a directory to the new location, I used ShFileOperation function. Important: if you want to copy only the content of the folder and not the folder itself, the StrFrom parameter should end with *.* like C:\MyTestFolder\sourceFolder\*.*


function TInstallationController.CopyDirectory(FormHandle : THandle;
        StrFrom, StrTo : string;
        BlnSilent : Boolean = False) : Boolean;
var
  F : TShFileOpStruct;
begin
  F.Wnd:=FormHandle;
  F.wFunc:=FO_COPY;
  F.pFrom:=PChar(StrFrom + #0);
  F.pTo:=PChar(StrTo+#0);
  F.fFlags := FOF_ALLOWUNDO or FOF_NOCONFIRMATION;
  if BlnSilent then
    F.fFlags := F.fFlags or FOF_SILENT;
  if ShFileOperation(F)  0 then
    result:=False
  else
    result:=True;
end;


Comments to the Post

Leave a Reply

For spam detection purposes, please copy the number 8207 to the field below: