MATLAB: Does the MCC command not create output directories specified using “-d” option if they do not exist when using MATLAB Compiler 4.11 (R2009b)

%fdistribMATLAB Compilermccsrc

I am using MATLAB Compiler 4.11 (R2009b) to create a standalone application from my MATLAB function "myfun.m" using the following command:
mcc -m -v myfun.m -d 'C:\work\myDir'
However, I receive the following error message:
??? Error using ==> mcc
The output directory,
'C:\work\myDir'
does not exist.
I would like the MCC command to create the output directory if it currently does not exist instead of generating this error message. This is would be very useful for me because my workflow requires me to compile the standalone application at the end of every day incorporating any changes made to my function and place the output in a folder whose name contains a datestamp.
This would also be a good feature to have when compiling project files created using DEPLOYTOOL using the following command:
mcc -F myApp.prj
Currently, I have to manually create the "src" and "distrib" directories to ensure that there is no error.

Best Answer

The ability to create the output directory specified using the "-d" option in the MCC command if it does not exist is not available in MATLAB Compiler 4.11 (R2009b).
To work around the issue, you can perform the following steps:
1. If you are using the MCC command to compile MATLAB functions directly, you create use the MKDIR command as specified below:
myDir = 'C:\work\myDir';
mkdir(myDir);
mcc('-m', 'myFunc.m', '-v', '-d', myDir);
2. If you are using the MCC command to compile a project file created using DEPLOYTOOL, you can use the following code to parse the project file and create the "src" and "distrib" directories.
s = 'myApp.prj';
prjFileName = s;
prj=xmlread(s);
s=['mcc -F ' s];
pathStr = fileparts( which(prjFileName) );
% Create the src directory
src_dir = prj.getElementsByTagName('intermediate_dir');
src_dir = src_dir.item(0).getFirstChild.getData;
src_dir = char(src_dir);
if ~isempty( regexp(src_dir, '\$\(PROJECTDIR\)', 'once') )
src_dir = regexprep(src_dir, '\$\(PROJECTDIR\)', '');
src_dir = fullfile(pathStr, src_dir);
end
mkdir(src_dir);
% Create the distrib directory
distrib_dir = prj.getElementsByTagName('output_dir');
distrib_dir = distrib_dir.item(0).getFirstChild.getData;
distrib_dir = char(distrib_dir);
if ~isempty( regexp(distrib_dir, '\$\(PROJECTDIR\)', 'once') )
distrib_dir = regexprep(distrib_dir, '\$\(PROJECTDIR\)', '');
distrib_dir = fullfile(pathStr, distrib_dir);
end
mkdir(distrib_dir);
% Evaluate the command
eval(s)