5 Şubat 2012 Pazar

Copy File or Directory

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;

Hiç yorum yok:

Yorum Gönder