Since R2017b the command isfolder is available and safer than exist('dir').
A problem of your approach is the usage of relative path names. Remember that a GUI or TIMER callback can change the current directory unexpectedly. In parallel programming this is a common problem also. So the solution is easy: Never work with relative paths.
A clean version:
base = 'C:\';
mkdir(fullfile(base, 'a', 'b', 'c');
want = 'C:/a/b/c';
isfolder(fullfile(want, 'b\c'))
isfolder(fullfile(base, 'b\c'))
Note, that any crazy callback cannot cofuse this by changing the current directory.
If do not understand, why exist('b/c','dir') returns 7, if the current folder is C:\a\b\c . Maybe b\c is existing anywhere in Matlab's path ? Remember that exist checks the complete path.
By the way, why do you assume, that
creates 'C:\a' and not the directory 'C:\a; cd a'
? It works as you expect it, but I do not know, where this is documented.
Best Answer