Reputation: 11
I want to make a installer for "unpacking" folders with files to a specific location – I done it with the Inno Setup wizard, but there is an issue because I would like to first check if folders with the name already exist, and if so rename the new ones:
Check if folder example
exist in location
– yes, rename new one to example_2
and put it into location
–- no, put example
into location
.
I discovered in help file that there is a function int DirExists
but no example etc. And I don't know how to use it properly :(
Upvotes: 1
Views: 67
Reputation: 202118
Use a scripted constant to implement unique destination path resolution with a use if DirExists
support function:
[Files]
Source: "subdir\*"; DestDir: "{code:GetUniquePath}";
[Code]
var
UniqueName: string;
function GetUniquePath(Param: string): string;
var
BasePath: string;
I: Integer;
begin
if UniqueName = '' then
begin
I := 2;
BasePath := ExpandConstant('{app}\subdir');
UniqueName := BasePath;
while DirExists(UniqueName) do
begin
UniqueName := BasePath + '_' + IntToStr(I);
Inc(I);
end;
Log('Unique destination path resolved to: ' + UniqueName);
end;
Result := UniqueName;
end;
The above code resolves the path on the first call (for the first file in the subfolder). Some may rather prefer resolving the path in advance, like shown in this similar question:
In Inno Setup choose a directory to install files from a pre-defined set
Upvotes: 1