Is it possible to ADD a warning before Matlab starts?

1 Ansicht (letzte 30 Tage)
Eric
Eric am 25 Jul. 2024
Kommentiert: dpb am 25 Jul. 2024
So, I have the previously-reported issue that, on startup in Windows 10, Matlab reports that any folders that are on mapped network drives (Z:, Y: etc.) are "nonexistent or not a directory". I also lose any scripts or functions from those mapped folders that were open in the editor when Matlab was last shut down, so I have to find and re-open them.
The hack to get around this is to access the network drive(s) in Microsoft Windows Explorer/File Explorer, after which Matlab can see the folders in those drives - e.g. if functions or scripts were loaded into the editor, these will appear following the above hack.
What I'd like is a warning, before Matlab goes off and fails to find those mapped network drives, reminding me to open the offending drives in Windows Explorer before continuing.
Is there any way to do this via startup.m - or would it need a Windows batch file to incorporate the warning and the pause?
  5 Kommentare
dpb
dpb am 25 Jul. 2024
"... the automatic reloading into the editor can't happen unless they are mapped at that time."
I haven't actually thought to test because I have the development environment on the local machine and only data files are on the shared drives, but I'd think if you simply typed edit after mapping the drives however that it would then load the previously open files again...unless it tries to be to clever and clears the past history of files that weren't available; that behavior I'm not sure about.
dpb
dpb am 25 Jul. 2024
"...trying to access the drives from the command prompt (i.e. in a batch file) before they have been "made available" in File Explorer just gives the error "The system cannot find the drive specified"."
Yes, you have to check in the .cmd file -- here's the outline of one -- there are those needed and then a mapAll that calls them all.
@echo off
net use H: \\mapdrive\path password|orletprompt /USER:username /PERSISTENT:YES
if %errorlevel%==0 (exit /b)
net use H: /DELETE >nul
net use H: \\mapdrive\path password|orletprompt /USER:username /PERSISTENT:YES
It could probably be more elegant with powershell if one could ever figure out how to write it, but .cmd works. As you note, while one would think one could use
if not exist H: ...
but as noted, if the drive doesn't exist, it errors. Hence the attempt to map it first and then test the error condition and exit if it succeeds. This has been quite robust for my situation if not, as above, elegant.
I had not thought about the file explorer "trick" -- it doesn't appear a way to call it that doesn't open the window, however.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Image Analyst
Image Analyst am 25 Jul. 2024
Bearbeitet: Image Analyst am 25 Jul. 2024
You can check for drives in your startup.m file, and warn you if the folder or drive is not there, like this
missingFolder = false;
folder = 'X:\';
if ~isfolder(folder)
warningMessage = sprintf('Warning: %s folder not found!', folder);
uiwait(warndlg(warningMessage));
missingFolder = true;
end
folder = 'Z:\my MATLAB files';
if ~isfolder(folder)
warningMessage = sprintf('Warning: %s folder not found!', folder);
uiwait(warndlg(warningMessage));
missingFolder = true;
end
if missingFolder
% Open File Explorer to the current folder if we didn't find one.
winopen(pwd);
end
If you have some top level folder where all your m-files live, even in subfolders, you can use the Setpath button on the tool ribbon to "Add with subfolders" the folder, then save the path. Or you can put this into your startup.m file:
folder = 'Z:\my MATLAB files';
addpath(genpath(folder));
savepath();
  1 Kommentar
Eric
Eric am 25 Jul. 2024
Nice. I'll try that tomorrow, but the suggestion looks promising.

Melden Sie sich an, um zu kommentieren.

Kategorien

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

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by