We’re moving our forums to a new platform.

You can still browse and search existing topics, but you can no longer create new topics or post replies.

For questions, technical issues, or feature requests, please don’t hesitate to contact our support team at support@advancedinstaller.com.

Thank you for your understanding!

ddeepti.kulkarni
Posts: 17
Joined: Mon Nov 09, 2015 11:13 am

How to get folder path containing specific file

Hello,

I want to get folder location containing specific folder on machine. For example if file is present on "C:\ABC\SearchFileName.txt" it should return "C:\ABC".
I want to show this path in folder dialogue installation path.
How this can be done?

Also can I search for XML, read specific tag value and show this path in folder dialogue installation path.

Thanks.
Dan
Posts: 4530
Joined: Wed Apr 24, 2013 3:51 pm

Re: How to get folder path containing specific file

Hello and welcome to Advanced Installer forums,
I want to get folder location containing specific folder on machine. For example if file is present on "C:\ABC\SearchFileName.txt" it should return "C:\ABC".
In order to search for a file on the target machine, you can go in the Search page and create a file search operation. Use the [ New Search Wizard ] toolbar button, to set up a new search, following step-by-step directions. If the search is successfully, then the property assigned to the Search operation will be set with the full path of the file (e.g. C:\ABC\SearchFileName.txt), otherwise it will be empty.

In order to retrieve the folder path, you need to create a custom action. Then, you can set the APPDIR with the folder path. A sample code that performs this, is the following:

Code: Select all

'retrieve the file path from the search operation
filePath = Session.Property ("RESULT_PROPERTY")

'if file is found on the target machine
If Len(filePath) > 0 Then

'retrieve folder path
folderPath = Left ( filePath, InStrRev (filePath, "\") - 1)

'set the installation path with this value
Session.Property ("APPDIR") = folderPath
End If
By the way, I've attached a sample project which implements this scenario, so if you are interested to take a look directly at my project, you are more than welcome to download the ZIP file.
Also can I search for XML, read specific tag value and show this path in folder dialogue installation path.
For this you can take a look on the Keep web.connfig settings from an older install path forum thread which debates this subject. You will also find a sample that implements your scenario.

Should there be any difficulty you encounter implementing something, please do not hesitate to contact me and I will gladly assist.

Best regards,
Dan
Attachments
GetFolder Sample.zip
(2.73 KiB) Downloaded 476 times
Dan Ghiorghita - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
ddeepti.kulkarni
Posts: 17
Joined: Mon Nov 09, 2015 11:13 am

Re: How to get folder path containing specific file

Hello Dan,

Thanks for your reply. This is helpful.
I would like to elaborate it further. I had asked if file is present on "C:\ABC\SearchFileName.txt" it should return "C:\ABC".
Here I want to actually search for "..\ABC\SearchFileName.txt" this ABC folder can be present anywhere like "D:\Temp\ABC\SearchFileName.txt" or "E:\Temp1\Temp2\ABC\SearchFileName.txt". "..\ABC\SearchFileName.txt" this path is fixed.

Is this possible?



Thanks.

Return to “Building Installers”