Mercurial > hg > ltpda
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/m-toolbox/classes/+utils/@prog/filescan.m Wed Nov 23 19:22:13 2011 +0100 @@ -0,0 +1,46 @@ +% FILESCAN recursively scans the given directory for files that end in 'ext' +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% DESCRIPTION: FILESCAN recursively scans the given directory for files +% that end in 'ext' and returns a list of the full paths. +% +% CALL: files = filescan(root_dir, ext) +% +% INPUTS: root_dir - directory +% ext - extension of a file (or cell-array of extensions) +% +% OUTPUTS: files - the found file names +% +% VERSION: $Id: filescan.m,v 1.4 2010/05/07 10:25:24 hewitson Exp $ +% +% HISTORY: 26-01-2007 M Hewitson +% Creation +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function files = filescan(root_dir, ext) + files = getfiles(root_dir, ext, []); +end + +%-------------------------------------------------------------------------- +function ofiles = getfiles(root_dir, iext, ofiles) + % Recursive function for getting file lists + % + + files = dir(root_dir); + + for j=1:length(files) + if files(j).isdir + if strcmp(files(j).name,'.')==0 && strcmp(files(j).name,'..')==0 + ofiles = getfiles([root_dir '/' files(j).name], iext, ofiles); + end + else + parts = regexp(files(j).name, '\.', 'split'); + ext = ['.' parts{end}]; + if any(strcmp(ext, iext)) + ofiles = [ofiles; {[root_dir '/' files(j).name]}]; + end + end + end +end +% END \ No newline at end of file