Created
March 31, 2012 22:59
-
-
Save ferryzhou/2269380 to your computer and use it in GitHub Desktop.
matlab mkdir if not exist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function mkdir_if_not_exist(dirpath) | |
if dirpath(end) ~= '/', dirpath = [dirpath '/']; end | |
if (exist(dirpath, 'dir') == 0), mkdir(dirpath); end | |
end |
Thank you Zhou and Sirius27
For creating a single directory at the level of the script where this code is called, I found it cleaner to use a one-liner, rather than define a function:
if (~exist('<folder_name>', 'dir')); mkdir('<folder_name>'); end%if
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi ferry you can simplify the code a little bit:
if ~exist(dirpath,'dir') mkdir(dirpath); end