How to get the path of the resource file folder of a packaged app

27 views (last 30 days)
Pietro Ungar
Pietro Ungar on 9 Feb 2020
Answered: Simone Parisotto on 2 Dec 2020
I'm trying to create a simple app that copy a default excel file from his resource folder to a folder selected by the user,
I've inserted the excel file in "shared resources and helper files" while packagine the app and it works because fhe file is in the higlighted (in the screenshot) folder afther the installation of the app.
The problem is that I can find a way to access that file (attached there's the code that works when I run the app from the App Designer, but fails when called from the app bar afther the installation),
so that's my question:
Is there a function in Matlab that returns the resource files folder path (the one higlighted in the photo) of the current application?
Is there another way to get that path?
I don't want to copy that path myself because I had to share this application and I suppose that Windows or Linux store those file in different locations
That's my code:
(displaySystemMessage is a function that I had defined to display messages on a textView)
function PasteDefaultExcelSheetButtonPushed(app, event)
errorFound = false;
defaultExcelPath = "Default Excel Input.xlsm";
selectedFolderPath = uigetdir();
copyfile(defaultExcelPath, selectedFolderPath);
catch error
errorFound = true;
app.displaySystemMessage("ERRORE", [error.identifier, newline, error.message]);
if ~errorFound
app.displaySystemMessage('STATUS', ['Default Excel File Copied from:', newline, defaultExcelPath]);
That's the screenshot:
(higlighted the folder that I want to access)

Answers (1)

Simone Parisotto
Simone Parisotto on 2 Dec 2020
you can try the following:
rootSettings = matlab.internal.getSettingsRoot;
addonFolder = rootSettings.matlab.addons.InstallationFolder.ActiveValue;
executableFolder = fullfile(addonFolder,'Apps',name_of_your_app);
Hope it helps!



Community Treasure Hunt

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

Start Hunting!