Reputation: 33
I trying to compile a little setup program for future users, I have understood how change some stuff.
But now I would like to create a shortcut ONLY if the directory exist. I tried to do something like that but nothing happened ... :
[Icons]
; Start menu icon
Name: "{group}\Myprogram"; Filename: "{app}\Myprogram.exe"
; Desktop icon
Name: "{userdesktop}\Myprogram.exe"; Filename: "{app}\Myprogram.exe"; \
Check: DirExists(ExpandConstant('C:\[path]\test'))
Upvotes: 1
Views: 163
Reputation: 202514
Your code is ok. It should do what you want. To help with the debugging, implement a user function that logs the test like:
[Icons]
Name: "{userdesktop}\P680.exe"; Filename: "{app}\P680.exe"; \
Check: DirExistsLogged('C:\Users\administrator\Documents\Test')
[Code]
function DirExistsLogged(Path: string): Boolean;
begin
Result := DirExists(Path);
Log(Format('DirExists [%s] => %d', [Path, Result]));
end;
Log example, when the folder exists:
2019-12-31 15:04:59.565 DirExists [C:\Users\administrator\Documents\Test] => 1
2019-12-31 15:04:59.565 -- Icon entry --
2019-12-31 15:04:59.565 Dest filename: C:\Users\martin\Desktop\My Program.exe.lnk
2019-12-31 15:04:59.566 Creating the icon.
2019-12-31 15:04:59.583 Successfully created the icon.
2019-12-31 15:04:59.594 Saving uninstall information.
Log example, when the folder does not exist:
2019-12-31 15:06:23.960 DirExists [C:\Users\administrator\Documents\Test] => 0
2019-12-31 15:06:23.960 Saving uninstall information.
Upvotes: 0