0001 function mkdirs(dirPath)
0002
0003
0004
0005
0006
0007 if nargin<1, selfdemo; return; end
0008
0009 newPath=strrep(dirPath, '\', '/');
0010 terms=split(newPath, '/');
0011
0012 if newPath(1)=='/'
0013 terms{1}=['/', terms{1}];
0014 end
0015 if ~isempty(strfind(terms{1}, ':'))
0016 terms{1}=[terms{1}, '/', terms{2}];
0017 terms(2)=[];
0018 end
0019
0020
0021 for i=1:length(terms)
0022 dirName=join(terms(1:i), '/');
0023 if exist(dirName)~=7
0024 fprintf('Make directory %s\n', dirName);
0025 mkdir(dirName);
0026 end
0027
0028 end
0029
0030
0031 function selfdemo
0032 dirPath='d:/users/jang/temp/junk/test';
0033 mkdirs(dirPath);
0034 fprintf(['Use "rmdir(''', 'd:/users/jang/temp/junk', ''', ''s'')" to remove junk directory and everything under it.\n']);