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

38 次查看(过去 30 天)
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 个评论
Edmond Dantes
Edmond Dantes 2021-6-2
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 2021-6-3
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.

请先登录,再进行评论。

回答(1 个)

Rik
Rik 2021-6-2
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 个评论
Edmond Dantes
Edmond Dantes 2021-6-5
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 2021-6-5
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by