unit main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ShellAPI;
type
TForm1 = class(TForm)
cmd_start: TButton;
procedure cmd_startClick(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
Function DeleteDir(DirName : string): Boolean;
function Sh_FileCopyMove(aWND: HWND; const Source,Dest: string; DoMove: boolean;
var IsAborted: boolean; Flags: FILEOP_FLAGS=0): Boolean;
var
Form1: TForm1;
const
backup_this = 'R:\';
backup_new = 'C:\Backup-FSS';
backup_old = 'C:\Backup-FSS(Old)';
implementation
{$R *.dfm}
procedure TForm1.cmd_startClick(Sender: TObject);
var
IsAborted: boolean;
begin
// rd /s /q Backup-FSS(Old)
if DirectoryExists(backup_old) then DeleteDir(backup_old);
// ren Backup-FSS Backup-FSS(Old)
if DirectoryExists(backup_new) then MoveFile(backup_old, backup_new);
// md Backup-FSS
// xcopy "R:\*.*" .\Backup-FSS\ /e
Sh_FileCopyMove(
Handle, backup_this, backup_new, False, IsAborted)
end;
//-----------------------------------------------------
Function DeleteDir(DirName : string): Boolean;
var
SHFileOpStruct : TSHFileOpStruct;
DirBuf : array [0..255] of char;
begin
try
Fillchar(SHFileOpStruct,Sizeof(SHFileOpStruct),0) ;
FillChar(DirBuf, Sizeof(DirBuf), 0 ) ;
StrPCopy(DirBuf, DirName) ;
with SHFileOpStruct do begin
Wnd := 0;
pFrom := @DirBuf;
wFunc := FO_DELETE;
fFlags := FOF_ALLOWUNDO;
fFlags := fFlags or FOF_NOCONFIRMATION;
fFlags := fFlags or FOF_SILENT;
end;
Result := (SHFileOperation(SHFileOpStruct) = 0) ;
except
Result := False;
end;
end;
//-----------------------------------------------------
function Sh_FileCopyMove(aWND: HWND; const Source,Dest: string; DoMove: boolean;
var IsAborted: boolean; Flags: FILEOP_FLAGS=0): Boolean;
var
fos : TSHFileOpStruct;
s,d: String;
begin
Result:= False;
if (Source='') or (Dest='') then exit;
s:= Source;
d:= Dest;
if Source[Length(S)]<> #0 then S:=S+ #0;
if D[Length(D)]<> #0 then D:=D+ #0;
ZeroMemory(@fos,SizeOf(fos));
with fos do
begin
Wnd:= aWND;
If DoMove then wFunc:= FO_Move
else wFunc:= FO_COPY;
//Flags auf 1, da ich Fehler sehen will ...
if Flags=1 then fFlags:=FOF_NOCONFIRMMKDIR or FOF_NOCONFIRMATION or FOF_SILENT or FOF_NOERRORUI
else fFlags:=Flags;
fAnyOperationsAborted:= IsAborted;
pFrom:=PChar(S);
pTo:=PChar(D);
end;
Result:= SHFileOperation(fos)=0;
IsAborted:= fos.fAnyOperationsAborted;
end;
end.