matlab standalone application default directory is cache directory
11 views (last 30 days)
Show older comments
Harshula Tulapurkar
on 17 Jan 2017
Commented: Walter Roberson
on 17 Jan 2017
I have developed an application on Mac OSX 10.9.5 which requires reading and writing files to directory relative to current directory. When i built a standalone application i find that the current directory is some cache directory. so all read and writes are relative to that directly. How do i set working directory? Can I have an interface to define the directories.
0 Comments
Accepted Answer
Walter Roberson
on 17 Jan 2017
OS-X graphics apps do not really have a "current" directory at start time, in useful sense. They are started from the desktop or one of the explorer windows, and so are independent of any "current" directory that user might have -- the user might have a number of different "current" directories in different windows the user has open.
OS-X non-graphics apps that are started from the command line might have a meaningful "current" directory, since they would have to be started from a shell: is that a situation relevant to you?
2 Comments
Walter Roberson
on 17 Jan 2017
Notice the guidance,
A compiled application behaves more consistently if it:
- Does not change any path during execution.
- Uses relative paths (or anchors paths to a known root via the matlabroot or ctfroot functions).
- Avoids accessing or changing the current directory.
I would suggest, then, that if you do put something in startup then it should be a variable indicating which directory to use (for something) but do not actually cd() to there. And remember that when other people use the application their startup.m is not going to be looked at, so it is not clear that putting code into startup.m is a good idea compared to putting it into a clearly labeled initialization file that is compiled into the application.
For finding the path of the executable at run time, see http://stackoverflow.com/questions/1023306/finding-current-executables-path-without-proc-self-exe
More Answers (0)
See Also
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!