This website uses cookies. By clicking Accept, you consent to the use of cookies. Click Here to learn more about how we use cookies.
Turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
- Revenera Community
- :
- InstallShield
- :
- InstallShield Forum
- :
- File Search
Subscribe
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎May 23, 2008
12:54 PM
Checking whether a file exists
Hoping somebody out there might be able to lend some assistance...
I have a Basic MSI install that I am developing that needs to check whether or not a particular file exists.
I'm using a custom dialog that prompts the user for a folder location (totally separate from the dialog which sets INSTALLDIR). Once they select the folder, I need to verify that it is the correct one by making sure a particular file exits. If the file doesn't exist, then it needs to prevent them from continuing with the install.
I don't believe (at least as I understand it) that System Search would work because this takes place before the user interface.
Any thoughts would be greatly appreciated.
Matt Adair
I have a Basic MSI install that I am developing that needs to check whether or not a particular file exists.
I'm using a custom dialog that prompts the user for a folder location (totally separate from the dialog which sets INSTALLDIR). Once they select the folder, I need to verify that it is the correct one by making sure a particular file exits. If the file doesn't exist, then it needs to prevent them from continuing with the install.
I don't believe (at least as I understand it) that System Search would work because this takes place before the user interface.
Any thoughts would be greatly appreciated.
Matt Adair
(2) Replies
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎May 23, 2008
02:19 PM
Correct, the system search might not be the best approach; if you're not averse to InstallScript custom actions, the Is(FILE_EXISTS, ...) function might be of use.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎May 23, 2008
02:27 PM
You probably already have a property defined for the folder browse location in your dialog. Make sure you define a directory of the same name in the directory table.
It is a good idea to preset this directory for the browse with a system search. This will happen before the install begins and it will initialize the value for the folder, preventing errors in your browse. Also define another property like "MYFOLDERFOUND" that you can use for a flag.
The installscript to check the value will look something like this:
export prototype CheckForFile(HWND);
function CheckForFile(hMSI)
STRING sFolder, sFilename;
NUMBER nSize;
begin
try
MsiGetProperty(hMSI, "MYFOLDER", sFolder, nSize);
sFilename = sFolder ^ "SomeFile";
if (Is(FILE_EXISTS, sFilename) = 1) then
MsiSetProperty(hMSI, "MYFOLDER", sFolder );
MsiSetProperty(hMSI, "MYFILEFOUND", "True");
else
SprintfBox(SEVERE, "Invalid Folder", "File could not be located at %s", sFolder);
MsiSetProperty(hMSI, "MYFILEFOUND", "False");
endif;
catch
endcatch;
end;
On the dialog Next events, set the first action to be a call to the custom action above which will check the value. Then condition the New Dialog event which follows with MYFILEFOUND = "True".
If the user selects the correct path for the file, the value is true and they can move ahead in the dialogs. If they pick a wrong folder, the value is false and they get a message telling them it is wrong and they can't continue. They must either pick a correct folder or cancel.
You may also want to consider checking the value in a separate customer action very early in the install to see if system search was able to locate the file at the default location. If it did, you can avoid even showing the browse dialog at all.
Hope this helps.
It is a good idea to preset this directory for the browse with a system search. This will happen before the install begins and it will initialize the value for the folder, preventing errors in your browse. Also define another property like "MYFOLDERFOUND" that you can use for a flag.
The installscript to check the value will look something like this:
export prototype CheckForFile(HWND);
function CheckForFile(hMSI)
STRING sFolder, sFilename;
NUMBER nSize;
begin
try
MsiGetProperty(hMSI, "MYFOLDER", sFolder, nSize);
sFilename = sFolder ^ "SomeFile";
if (Is(FILE_EXISTS, sFilename) = 1) then
MsiSetProperty(hMSI, "MYFOLDER", sFolder );
MsiSetProperty(hMSI, "MYFILEFOUND", "True");
else
SprintfBox(SEVERE, "Invalid Folder", "File could not be located at %s", sFolder);
MsiSetProperty(hMSI, "MYFILEFOUND", "False");
endif;
catch
endcatch;
end;
On the dialog Next events, set the first action to be a call to the custom action above which will check the value. Then condition the New Dialog event which follows with MYFILEFOUND = "True".
If the user selects the correct path for the file, the value is true and they can move ahead in the dialogs. If they pick a wrong folder, the value is false and they get a message telling them it is wrong and they can't continue. They must either pick a correct folder or cancel.
You may also want to consider checking the value in a separate customer action very early in the install to see if system search was able to locate the file at the default location. If it did, you can avoid even showing the browse dialog at all.
Hope this helps.
![](/skins/images/8C9D13A71C7F7695F3262372C0172D68/responsive_peak/images/icon_anonymous_message.png)