Is it possible to ADD a warning before Matlab starts?
Mostra commenti meno recenti
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 Commenti
Eric
il 25 Lug 2024
To reach the college network drives unless am logged into a college machine directly, I have to first connect through the VPN and map the drives; sounds as if you've got something slimilar going on. I have a batch file that does that which I run first when needing to be able to get to those drives. I haven't seen that it matters whether MATLAB is running or not; mapping the drives makes them visible after a session starts although, granted, the automatic reloading into the editor can't happen unless they are mapped at that time.
I've not trie tried it, but I suppose one could add a msgbox to the startup.m file to do the same thing as what the above batch file does; I do not know for certain about the sequence of starting up, however; whether the code to reload the editor will be before or after that little bit. Don't think it can hurt to try, however...
Eric
il 25 Lug 2024
dpb
il 25 Lug 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
il 25 Lug 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.
Risposte (1)
Image Analyst
il 25 Lug 2024
Modificato: Image Analyst
il 25 Lug 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 Commento
Eric
il 25 Lug 2024
Categorie
Scopri di più su Startup and Shutdown in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!