comparison m-toolbox/classes/+utils/@prog/dirscan.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 % DIRSCAN recursively scans the given directory for subdirectories that
2 % match the given pattern.
3 %
4 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5 %
6 % DESCRIPTION: DIRSCAN recursively scans the given directory for subdirectories that
7 % match the given pattern.
8 %
9 % CALL: files = dirscan(root_dir, pattern)
10 %
11 % INPUTS: root_dir - directory
12 % pattern - regexp pattern to match
13 %
14 % OUTPUTS: dirs - the found directory names
15 %
16 % VERSION: $Id: dirscan.m,v 1.2 2010/10/07 14:57:40 hewitson Exp $
17 %
18 % HISTORY: 26-01-2007 M Hewitson
19 % Creation
20 %
21 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22 function dirs = dirscan(root_dir, pattern)
23 dirs = getdirs(root_dir, pattern, []);
24 end
25
26 %--------------------------------------------------------------------------
27 function odirs = getdirs(root_dir, pattern, odirs)
28 % Recursive function for getting file lists
29 %
30
31 files = dir(root_dir);
32
33 for j=1:length(files)
34 if files(j).isdir
35
36 % add this dir if the pattern matches
37 if ~isempty(regexp(files(j).name, pattern, 'match'))
38 odirs = [odirs {fullfile(root_dir, files(j).name)}];
39 end
40 % and look inside
41 if strcmp(files(j).name,'.')==0 && strcmp(files(j).name,'..')==0
42 odirs = getdirs(fullfile(root_dir, files(j).name), pattern, odirs);
43 end
44
45 end
46 end
47 end
48 % END