Mega Code Archive

 
Categories / Delphi / Examples
 

Copy files with windows progress

How to copy multiple / large files and show the windows progress form. (Make sure ShellAPI is in your USES list) Source and Dest are both a list of files separated with #0, for example WinCopyFile('c:\1.txt' + #0 + 'c:\2.txt', 'a:\1.txt' + #0 + 'a:\2.txt'); function WinCopyFile(Source, Dest: string): Boolean; var Struct : TSHFileOpStruct; Resultval: integer; begin ResultVal := 1; try Source := Source + #0#0; Dest := Dest + #0#0; Struct.wnd := 0; Struct.wFunc := FO_COPY; Struct.pFrom := PChar(Source); Struct.pTo := PChar(Dest); Struct.fFlags:= FOF_SIMPLEPROGRESS or FOF_NOERRORUI or FOF_NOCONFIRMATION; Struct.fAnyOperationsAborted := False; Struct.hNameMappings := nil; Resultval := ShFileOperation(Struct); finally Result := (Resultval = 0); end; end;