Code :
- //CopyAllFiles() will copy a set of files or a directory of your choice.
- // It also displays the same animation of the operation as does Windows Explorer.
- //You can pass wildcards to the function. In order to copy a directory, do not include the last
- backslash.
- //For example: CopyAllFiles('C:\ThisDirectory', 'C:\AnotherDirectory', False);
- //The 'False' parameter tells the function to not rename files if they already exist.
- // If set to 'True', the new files will have 'Copy of ...' appended to the name. }
- uses ShellAPI;
- function CopyAllFiles(sFrom, sTo: string; Protect: boolean): boolean;
- { Copies files or directory to another directory. }
- var
- F: TShFileOpStruct;
- ResultVal: integer;
- tmp1, tmp2: string;
- begin
- FillChar(F, SizeOf(F), #0);
- Screen.Cursor := crHourGlass;
- try
- F.Wnd := 0;
- F.wFunc := FO_COPY;
- { Add an extra null char }
- tmp1 := sFrom + #0;
- tmp2 := sTo + #0;
- F.pFrom := PChar(tmp1);
- F.pTo := PChar(tmp2);
- if Protect then
- F.fFlags := FOF_RENAMEONCOLLISION or FOF_SIMPLEPROGRESS
- else
- F.fFlags := FOF_SIMPLEPROGRESS;
- F.fAnyOperationsAborted := False;
- F.hNameMappings := nil;
- Resultval := ShFileOperation(F);
- Result := (ResultVal = 0);
- finally
- Screen.Cursor := crDefault;
- end;
- end;
|