How to get the user's installation path in my app designer?

56 visualizzazioni (ultimi 30 giorni)
When I use app designer, I want to create some folder in the installation path when someone is using my app. How can I get the installation path where my app is installed?
For example, someone installs my app in 'C:\Program Files\myapp', I want to create a folder in this path to save some compute results. How can I get this installation path when I am coding by app designer?
  3 Commenti
Edmond Dantes
Edmond Dantes il 2 Giu 2021
mfilename returns a path similar to C:\Users\<usrname>\AppData\Local\Temp\<usrname>\mcrCache9.10\myapp
and I am also wandering why the config files published with my app are also in this path, rather than in 'C:\Program Files\myapp'
Edmond Dantes
Edmond Dantes il 3 Giu 2021
I have tried many ways to get the installation path, such as 'mfilename', 'dbstack('-completenames')', evalin('caller', strcat('which(''', 'myapp', ''')')). But they all return the same path similar to 'C:\Users\<usrname>\AppData\Local\Temp\<usrname>\mcrCache9.10\myapp'.
However the app is installed in 'C:\Program Files\myapp'. The exe file is in the path 'C:\Program Files\myapp\application\myapp.exe'.
It is really confusing why I cannot get the real installation path.

Accedi per commentare.

Risposte (1)

Rik
Rik il 2 Giu 2021
If you want more control over where your persistent files are stored, I would suggest the GetWritableFolder.
This will generate a path that is persistent across versions of Matlab and across calls. This is what I currently use if I want to persistently store configurations.
f=GetWritableFolder('ForceStatus',1);
  6 Commenti
Edmond Dantes
Edmond Dantes il 5 Giu 2021
I'm afraid you may not get my problem. It has no concern with privileges.
I just want to get the installation path, and save some results in the user's installation path.
It is a string such as the return of the function 'mfilename'.
In other word: someone installs myapp in some path, such as 'C:\Program Files\myapp', and input '1' and '2' in the UI of my app. I want to save '3' in a txt file in the path 'C:\Program Files\myapp'. Which function can return where my app is installed? i.e. which function can return the string 'C:\Program Files\myapp'?
If I can get the path string, I can save a txt file in the path. Otherwise, the file may be saved in an unpredictability path.
Rik
Rik il 5 Giu 2021
It does have to do with privileges. If the user installs your app as admin (and puts it in a location where you need admin privileges to write), and then runs your app as a normal user, you're stuck. If you use my function you are guaranteed the same path every time, and you should have write access as any user.
I don't know if there is a function that will return the installation folder (maybe matlabroot gets modified?), but you shouldn't be using that anyway. The %APPDATA% folder shortcut exists for a reason.

Accedi per commentare.

Categorie

Scopri di più su Introduction to Installation and Licensing in Help Center e File Exchange

Prodotti


Release

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by