How do I lock the current directory while a GUI-based program is running?

2 views (last 30 days)
Hello, I've got a large GUI-based program that I'd like to error-proof by ensuring that the user doesn't change the current directory.
E.g., if she changes the directory, and then tries to close the program, an error comes up because MATLAB can no longer find the CloseRequestFcn. :( Same goes for countless other cases.
Any idea how this might be done? (My backup plan is to just make the main GUI window modal, preventing any other MATLAB window from being selected.)

Accepted Answer

Jan
Jan on 23 Mar 2012
Modal dialogs are not user-friendly, therefore I recommend to avoid this feature whenever it is possible.
Arthur's suggestion to add the folder to the Matlab path is the standard solution for finding functions in a specific folder.
further methods are nested functions and the creation of function handles to all subfunctions during the creation of the GUI. These function handles are independent from the current folder.
  1 Comment
Alex
Alex on 27 Mar 2012
Hi Jan, thanks for the reply. I agree that modal dialogs aren't ideal. The idea of creating function handles during the creation of the GUI (presumably with path information) sounds perfect, thanks!

Sign in to comment.

More Answers (2)

Arthur
Arthur on 23 Mar 2012
Why don't you simply add your path to the MATLAB search pad? Then you'll never have this problem. If you want, you can even add this to the openingFcn of your GUI.
doc addpath
GUI_script = mfilename(); %name of the file
GUI_path = mfilename('fullpath'); %full path including filename
GUI_path = regexprep(GUI_path,GUI_script,'');%full path without file name
%add GUI path to search pad
addpath(GUI_path)

SAIM  HAQUE
SAIM HAQUE on 23 Mar 2012
hello, ALEX, i'have some suggestion, just right click to any folder, and select "ADD PATH"-->"Select folders and sub folders".
In this way, you place m-file into any other folder and acceess it easily.

Categories

Find more on Search Path 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!