comparison m-toolbox/classes/+utils/@prog/filescan.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 % FILESCAN recursively scans the given directory for files that end in 'ext'
2 %
3 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4 %
5 % DESCRIPTION: FILESCAN recursively scans the given directory for files
6 % that end in 'ext' and returns a list of the full paths.
7 %
8 % CALL: files = filescan(root_dir, ext)
9 %
10 % INPUTS: root_dir - directory
11 % ext - extension of a file (or cell-array of extensions)
12 %
13 % OUTPUTS: files - the found file names
14 %
15 % VERSION: $Id: filescan.m,v 1.4 2010/05/07 10:25:24 hewitson Exp $
16 %
17 % HISTORY: 26-01-2007 M Hewitson
18 % Creation
19 %
20 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21 function files = filescan(root_dir, ext)
22 files = getfiles(root_dir, ext, []);
23 end
24
25 %--------------------------------------------------------------------------
26 function ofiles = getfiles(root_dir, iext, ofiles)
27 % Recursive function for getting file lists
28 %
29
30 files = dir(root_dir);
31
32 for j=1:length(files)
33 if files(j).isdir
34 if strcmp(files(j).name,'.')==0 && strcmp(files(j).name,'..')==0
35 ofiles = getfiles([root_dir '/' files(j).name], iext, ofiles);
36 end
37 else
38 parts = regexp(files(j).name, '\.', 'split');
39 ext = ['.' parts{end}];
40 if any(strcmp(ext, iext))
41 ofiles = [ofiles; {[root_dir '/' files(j).name]}];
42 end
43 end
44 end
45 end
46 % END