Copy a directory (and its subdirectories and files)  

Send By: Radikal (Q3 Team)
Web : http://www.q3.nu
Email: radikal@q3.nu
Date: 30/08/20

Tip accessed 611 times

 


We will use the function API ShFileOperation. You look at yourself the help of this function, since it allows several options just as not showing the progress of the copy, to allow or non UNDO, etc...

  • Include ShellApi in the uses line.


     procedure TForm1.Button1Click(Sender: TObject);
    
       function CopiaTodo(Origen,Destino : String) :
       LongInt;
       var
         F : TShFileOpStruct;
         sOrigen, sDestino : String;
       begin
         Result := 0;
         sOrigen := Origen + #0;
         sDestino := Destino + #0;
    
         with F do
         begin
           Wnd   := Application.Handle;
           wFunc := FO_COPY;
           pFrom := @sOrigen[1];
           pTo   := @sDestino[1];
           fFlags := FOF_ALLOWUNDO or FOF_NOCONFIRMATION
         end;
    
         Result := ShFileOperation(F);
     end;
    
     begin
       CopiaTodo('c:\Delphi3\*.*','c:\kk');
     end;
    



    The help for this function is in the Win32.hlp file at your HD.


    Updated at 30/08/2002 (Uses ShellApi)