Basic_Coder
Posts: 12
Joined: Tue Jun 16, 2020 8:27 pm

Find if a specific file path exists on target machine

Advanced Installer,

Environment: Advanced Installer 15.3 Enterprise. Installer written on Win10 computer. Install Parameters demand that the package installs onto a computer higher than (not inclusive of) Windows XP.

I am trying to use a property as a true/false indicator of if a file exists on the target machine. This allows me to use it as a conditional in a File Copy/Move Operation. I have a file saved onto their system that I do not wish to overwrite, and doing a conditional based off a public property is the only way I know how to do this. If it were a regular installed file, I could use the Do Not Overwrite flag with a condition of 1 ( https://www.advancedinstaller.com/user- ... s-tab.html ) but I do not have that option ( https://www.advancedinstaller.com/user- ... ialog.html ). The file installed via a Permanent attribute component ( https://www.advancedinstaller.com/user- ... rties.html ) and I do not wish to overwrite it, even if there currently is no installation, so I cannot use OLD_PRODUCTS.

I am having issue as the only way I know how to do this is to use Custom Behavior > Search window > New File Search > Path: C:\ProgramData\Company\ProductLine\Product\CommonName.txt

This path saves to the .aip as <ROW Signature_="FileSearchSign" Path="[CommonAppDataFolder]" Depth="3"/>, and the GUI also reveals that it does not have any more information.

My trouble is that my ProductLine directory has ProductA\CommonName.txt and ProductB\CommonName.txt, and so just looking at the depth from CommonAppDataFolder will not work.

I have thought about having the conditional be NOT (MY_PROP = "C:\ProgramData\Company\ProductLine\Product\CommonName.txt") but 1) I'm doing this expression wrong and 2) this still means that the search could find the wrong file, and stop looking for the correct one, and so the wrong path will be returned.

My old installer was written years before I joined the company and uses a VBScript in InstallShield. I was really hoping to get away from a VBScript if possible.

Never Overwrite attribute, as I understand it, fails my use case because I am not guaranteed that past installations will have this flag.

The links viewtopic.php?t=9510 (File Search property) and https://www.advancedinstaller.com/user- ... rties.html seemed to be the closest related topic, along with many others have been invaluable as I figure out how to reverse engineer this InstallShield installer that I have, but alas I could not figure out this very specific case.
Catalin
Posts: 6592
Joined: Wed Jun 13, 2018 7:49 am

Re: Find if a specific file path exists on target machine

Hello and welcome to our forums,

To be fully honest with you, this is highly dependant on your scenario.

A solution I see to this would be to have multiple searches, for each "Product" folder you have, e.g.:

1 search for ProductA, 1 search for ProductB, etc.

This can be done as it follows:

- from our whole path, we will need to take a basic path for each of our searches. In the provided path, I'd say that the basic path would be:

Path: C:\ProgramData\Company\ProductLine\Product\CommonName.txt

Basic Path for first search: C:\ProgramData\Company\ProductLine\ProductA

Basic Path for second search: C:\ProgramData\Company\ProductLine\ProductB

In "Searches" page, you can create a "New File Search". After doing so, you can right click on the search --> "Add search location" --> "Folder" --> give the path to the "ProductA" folder, with a depth of "0".

The property that stores the result of the search will be populated with the full path, e.g.:

C:\ProgramData\Company\ProductLine\ProductA\CommonName.txt

Now, based on what file you are looking for, you can use a condition for your "File Copy/Move" operation such as it follows:

Code: Select all

RESULT_PROPERTY = "C:\ProgramData\Company\ProductLine\ProductA\CommonName.txt"
If I understand correctly, you want to be a little bit more "strict" in what regards the result of the search. Basically, you do not want to know only if the file exist, but strictly if the file you are looking for exists - as the file may be located in multiple locations.

I believe the above approach should work in your scenario, as the result of the search points exactly to the file in your specific folder.

Hope this helps.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Basic_Coder
Posts: 12
Joined: Tue Jun 16, 2020 8:27 pm

Re: Find if a specific file path exists on target machine

Thanks much, Catalin. That was an accurate assessment of my situation and what I wanted.
Catalin
Posts: 6592
Joined: Wed Jun 13, 2018 7:49 am

Re: Find if a specific file path exists on target machine

You are always welcome!

I am glad I was able to help.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”