MATLAB: Does the SYSTEM command fail when I use MKDIR or RMDIR even though the MATLAB MKDIR function works as expected in MATLAB 7.5 (R2007b)

MATLAB

I can create and remove folders in the current directory through Windows Explorer and MKDIR in MATLAB 7.5(R2007b). I also have administrator privileges on the machine. However, I am unable to create a new directory using the '!' operator or SYSTEM command with MKDIR as follows
!mkdir test
system('mkdir test');
There is no error message but the directory is not created. Additionally, I receive the following error when I build any model in SIMULINK 7.0 (R2007b):
??? Error using ==> cd
Cannot CD to C:\Documents and Settings\smithsd\My Documents\MATLAB\slprj\
(Name is nonexistent or not a directory).
Error in ==>
\\dal4techapps2\EAS_Apps\MATLAB_R2008b\toolbox\rtw\rtw\private\rtw_mk_dir.p>rtw_mk_dir
at 7
Error in ==>
\\dal4techapps2\EAS_Apps\MATLAB_R2008b\toolbox\rtw\rtw\private\rtw_create_directory_path.p>rtw_create_directory_path
at 24
Error in ==>
\\dal4techapps2\EAS_Apps\MATLAB_R2008b\toolbox\rtw\rtw\private\rtwinfomatman.p>save_method
at 458
Error in ==>
\\dal4techapps2\EAS_Apps\MATLAB_R2008b\toolbox\rtw\rtw\private\rtwinfomatman.p>rtwinfomatman
at 130
Error in ==>
\\dal4techapps2\EAS_Apps\MATLAB_R2008b\toolbox\rtw\rtw\private\rtwinfomatman.p>update_method
at 385
Error in ==>
\\dal4techapps2\EAS_Apps\MATLAB_R2008b\toolbox\rtw\rtw\private\rtwinfomatman.p>rtwinfomatman
at 139
Error in ==> rtwprivate at 12
[varargout{1:nargout}] = feval(function_name, varargin{1:end});
Error in ==> build_standalone_rtw_target at 18
minfo = rtwprivate('rtwinfomatman',pwd,'update','minfo',iMdl,'NONE');
Error in ==>
\\dal4techapps2\EAS_Apps\MATLAB_R2008b\toolbox\simulink\simulink\private\slbuild_private.p>loc_codegenentry
at 403

Best Answer

MATLAB calls CMD.EXE during execution of the built-in SYSTEM function for MKDIR and RMDIR.This executable is usually located in:
C:\WINNT\system32\cmd.exe
The value of the COMSPEC environment variable points to wherever CMD.EXE. It will error out if the environment variable does not point to the correct file. Changing COMSPEC environment variable from
C:\WINDOWS\system32\cmd.exe
to
C:\WINNT\system32\cmd.exe
will resolve the issue.