MATLAB Answers

Cannot remove folder that is on Matlab path from outside of Matlab

23 views (last 30 days)
Markus on 11 Feb 2019
Commented: dpb on 14 Jun 2019
we are using a library that adds folders to the Matlab path. In addition we have an external build system that tries to delete temporary folders before building mex-Files and copying Simulink and Matlab files. For an unknown reason, Matlab prevents the removal of these folder as long they are on the Matlab path. I tried bdclose('all'), clear functions, clear mex, clear all, nothing helps. Why is Matlab preventing the removal?
I also tried to reproduce it manually. But than it works. It happens only with folders that have been added by this library.


dpb on 11 Feb 2019
The latter is the klew that it is in the installation process of the library, not MATLAB itself that is setting the folder attributes, so dig into their install process/script.
Oh, another thought...ML for performance reasons caches the functions; normally |clear mex| lets development tools recompile and replace mex files; in what form is the library distributable; is it a DLL perchance? That may be locked by the system OS...
Rigel Ifland
Rigel Ifland on 14 Jun 2019
I'm also having this problem, and it's pretty frustrating because it means that if anyone adds my code (stored on a network drive) to their path, I can't delete it until they have closed MATLAB or removed it from their path.
I can reproduce the problem (which seems to do with packages) by creating a few files:
If I add demoFolder to the path, I can't delete it from outside MATLAB. Once I remove it from the path I can.
MATLAB 2018b, Windows 10
dpb on 14 Jun 2019
OTOH, it would be pretty frustrating for the user if they were using said code and all of a sudden it disappears in the middle of something they're doing, too...

Sign in to comment.

Answers (1)

Markus on 11 Feb 2019
No, it is mainly matlab and Simulink files. But the problem happens for any folder, no matter if it contains Simulink, Matlab or mex files


Sign in to comment.

Sign in to answer this question.

Translated by