view m-toolbox/classes/+utils/@prog/filescan.m @ 47:dd93c9ba6624
database-connection-manager
Fix Java dialog
author
Daniele Nicolodi <nicolodi@science.unitn.it>
date
Tue, 06 Dec 2011 19:07:27 +0100 (2011-12-06)
parents
f0afece42f48
children
line source
+ − % 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