IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
misc/ioio/getdirs.m
Go to the documentation of this file.
1 %>@file
2 %>@brief Recursive directory structure getter
3 %> @ingroup ioio
4 %
5 %> @param direc A directory to query all subdirectories from
6 %> @param list (optional) An existing list to which new elements will be appended
7 %> @param patt_match If specified, directories will have to match this pattern
8 %> @param patt_exclude If specified, directories will have NOT TO match this pattern
9 %> @return list
10 function list = getdirs(direc, list, patt_match, patt_exclude)
11 
12 if nargin < 1 || isempty(direc)
13  direc = '.';
14 end;
15 
16 if nargin < 2 || isempty(list)
17  list = {};
18 end;
19 
20 if nargin < 3
21  patt_match = [];
22 end;
23 if nargin < 4
24  patt_exclude = [];
25 end;
26 flag_match = ~isempty(patt_match);
27 flag_exclude = ~isempty(patt_exclude);
28 
29 d = dir(direc);
30 [vv, ii] = sort({d.name});
31 d = d(ii);
32 d = {d([d.isdir]).name};
33 d = {d{~ismember(d,{'.' '..'})}};
34 if flag_match
35  d = d(cellfun(@(x) ~isempty(x), regexp(d, patt_match, 'start')));
36 end;
37 if flag_exclude
38  d = d(cellfun(@isempty, regexp(d, patt_exclude, 'start')));
39 end;
40 for j=1:length(d)
41  if ~any(d{j}(1) == '@.')
42  ff = fullfile(direc,d{j});
43  list{end+1} = ff;
44  list = getdirs(ff,list, patt_match, patt_exclude);
45  end;
46 end
47 
function getdirs(in direc, in list, in patt_match, in patt_exclude)