Mega Code Archive

 
Categories / Delphi / Files
 

How to copy a folder with files inside

Title: How to copy a folder with files inside Question: How can I copy a folder that has files and subfolder inside it? Answer: This is how it is done: procedure TForm1.Button1Click(Sender: TObject); var Fo : TSHFileOpStruct; buffer : array[0..4096] of char; p : pchar; begin FillChar(Buffer, sizeof(Buffer), #0); p := @buffer; StrECopy(p, ''C:\MyDir\*.*''); //this is folder that you want to copy FillChar(Fo, sizeof(Fo), #0); Fo.Wnd := Handle; Fo.wFunc := FO_COPY; Fo.pFrom := @Buffer; Fo.pTo := ''C:\DestinationDir''; //this is where the folder will go Fo.fFlags := 0; if ((SHFileOperation(Fo) 0) or (Fo.fAnyOperationsAborted false)) then ShowMessage(''Cancelled'') end; This is my first article so i hope that i come in useful. James Sturrock