Home > utility > mkdirs.m

mkdirs

PURPOSE ^

mkdirs: Make several directories along a given path of all directories

SYNOPSIS ^

function mkdirs(dirPath)

DESCRIPTION ^

mkdirs: Make several directories along a given path of all directories
    Usage: mkdirs(dirPath)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function mkdirs(dirPath)
0002 %mkdirs: Make several directories along a given path of all directories
0003 %    Usage: mkdirs(dirPath)
0004 
0005 %    Roger Jang, 20090203, 20100204
0006 
0007 if nargin<1, selfdemo; return; end
0008 
0009 newPath=strrep(dirPath, '\', '/');    % Convert to unix format
0010 terms=split(newPath, '/');
0011 
0012 if newPath(1)=='/'    % newPath='/users/jang/batch'
0013     terms{1}=['/', terms{1}];
0014 end
0015 if ~isempty(strfind(terms{1}, ':'))    % newPath='d:/users/jang/batch'
0016     terms{1}=[terms{1}, '/', terms{2}];
0017     terms(2)=[];
0018 end
0019 
0020 % Create each dir
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 % ====== Self demo
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']);

Generated on Tue 01-Jun-2010 09:50:34 by m2html © 2003