2006. július 10., hétfő

Copy all Files in directory

Problem/Question/Abstract:

How to copy all Files inDirectory

Answer:

...copy / move / delete whole directory?
Autor: Rainer K�mmerle
Homepage: http://www.delphimania.de

uses
ShellApi;

function CopyDir(const fromDir, toDir: string): Boolean;
var
fos: TSHFileOpStruct;
begin
ZeroMemory(@fos, SizeOf(fos));
with fos do
begin
wFunc  := FO_COPY;
fFlags := FOF_FILESONLY;
pFrom  := PChar(fromDir + #0);
pTo    := PChar(toDir)
end;
Result := (0 = ShFileOperation(fos));
end;


function MoveDir(const fromDir, toDir: string): Boolean;
var
fos: TSHFileOpStruct;
begin
ZeroMemory(@fos, SizeOf(fos));
with fos do
begin
wFunc  := FO_MOVE;
fFlags := FOF_FILESONLY;
pFrom  := PChar(fromDir + #0);
pTo    := PChar(toDir)
end;
Result := (0 = ShFileOperation(fos));
end;

function DelDir(dir: string): Boolean;
var
fos: TSHFileOpStruct;
begin
ZeroMemory(@fos, SizeOf(fos));
with fos do
begin
wFunc  := FO_DELETE;
fFlags := FOF_SILENT or FOF_NOCONFIRMATION;
pFrom  := PChar(dir + #0);
end;
Result := (0 = ShFileOperation(fos));
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
if cCopyDir('d:\download', 'e:\') = True then
ShowMessage('Directory copied.');
end;

Nincsenek megjegyzések:

Megjegyzés küldése