Matlab Compiler: Is "userpath" always there and accessible?

Dear all,
my compiled app needs to store some temporary files in the background. Is it safe to assume that the directory given by userpath will exist on all computers? And that we will always have write access to this folder?
Thanks!!
William

3 Kommentare

Although MATLAB creates this folder on startup/userpath-reset there is nothing stopping a user from deleting that folder or changing its permissions.
Calling USERPATH RESET immediately before you need to use it might be sufficient to ensure that it exists. But there is not much you can do about the permissions: fundamentally folder permissions are something the OS controls, not MATLAB.
Thanks, I think this is safe enough for me. If someone really wants to break my tool by changing permissions or deleting folders, then he still can, and that is ok. I can still display an appropriate messagebox in this case.
Good point with the userpath reset, I'll add an
if isdeployed;userpath("reset");end
...well, userpath reset doesn't work with compiler unfortunately.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Steven Lord
Steven Lord am 27 Nov. 2024

0 Stimmen

I would probably try using the tempdir and/or tempname functions.

2 Kommentare

But tempdir doesn't always return a path, right? I have the feeling that userpath might be better, because this directory is apparently always created by Matlab Compiler.
It ought to return a folder name, unless perhaps a user has done something unusual with certain environmental variables. The documentation says that the folder is not guaranteed to exist, but you can check that with exist and use mkdir to create the directory if it does not exist yet.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Startup and Shutdown finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2024b

Gefragt:

am 27 Nov. 2024

Kommentiert:

am 30 Nov. 2024

Community Treasure Hunt

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

Start Hunting!

Translated by