Backup of application directory

From ISXKB

Jump to: navigation, search

Contents

Introduction

Sometimes it's useful to make a backup of an existing application directory before an update is applied.

The solution

With a little bit of [Code] Inno Setup's [Files] section can create a backup of an existing application folder before the files are overwritten.

The code

The following example copies the contents of the application's directory into a subfolder named 'Archive-YYYY-MM-DD hh.mm.ss'). On Windows a colon (':') cannot be part of a file name. That's why a dot is used here to separate hours and minutes.

The flag 'setntfscompression' ensures that the backup files are compressed if the file system is NTFS.

[Files]
Source: {app}\*; DestDir: {app}\Archive-{code:GetTodaysName}; Flags: external setntfscompression skipifsourcedoesntexist

[Code]
var
  TodaysName : String;

function GetToday : String;
begin
  Result := GetDateTimeString ('yyyy/mm/dd hh.nn.ss', '-', #0);
end;

function GetTodaysName (Param: String): String;
begin
  if ('' = TodaysName) then
  begin
    TodaysName := GetToday ();
  end;
  Result := TodaysName;
end;

When the application is uninstalled Inno Setup takes automatically care of the backup's removal.

See also

External links

Personal tools
Ads: