Daniel@0: function mkdirKPM(dname) Daniel@0: % function mkdirKPM(dname) Daniel@0: % If directory does not exist, make it Daniel@0: % Daniel@0: % mkdirKPM('foo\bar\baz') makes subdirectories bar and baz Daniel@0: % mkdirKPM('foo\bar\baz.txt') makes subdirectories bar Daniel@0: Daniel@0: % convert foo\bar\baz to pathstr=foo\bar, name=baz Daniel@0: % convert foo\bar\baz.txt to pathstr=foo\bar, name=baz Daniel@0: [pathstr, name, ext, versn] = fileparts(dname); Daniel@0: if ~isempty(ext) % we stripped off something after final period Daniel@0: % convert foo\bar to pathstr=foo, name=bar Daniel@0: % convert foo\bar.bad to pathstr=foo, name=bar.bad Daniel@0: [pathstr, name, ext, versn] = fileparts(pathstr); Daniel@0: name = sprintf('%s%s', name, ext); % in case there is a period in the directory name Daniel@0: end Daniel@0: Daniel@0: dname = fullfile(pathstr, name); Daniel@0: if ~exist(dname, 'dir') Daniel@0: %fprintf('mkdirKPM: making %s, %s \n', pathstr, name); Daniel@0: mkdir(pathstr, name) Daniel@0: else Daniel@0: %fprintf('mkdirKPM: %s already exists\n', dname) Daniel@0: end