Home > atmlab > files > getfiles_matching_regexp.m

getfiles_matching_regexp

PURPOSE ^

% getfiles_matching_regexp

SYNOPSIS ^

function files = getfiles_matching_regexp(datadir,regularexp)

DESCRIPTION ^

% getfiles_matching_regexp

 Purpose: List all files that match regular expression in directory and
 its subdirectories

 USAGE: files = getfiles_matching_regexp('directory','regexp')

 IN: 
     datadir   directory to look at   e.g. '.'
     regexp    regular expression     e.g. '.m$e4' ($ signals the end of the filename)



 OUT: files    cell of matching file names


 created by Salomon Eliasson
 $Id$

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

getfiles_matching_regexp.m

SOURCE CODE ^

0001 function files = getfiles_matching_regexp(datadir,regularexp)
0002 %% getfiles_matching_regexp
0003 %
0004 % Purpose: List all files that match regular expression in directory and
0005 % its subdirectories
0006 %
0007 % USAGE: files = getfiles_matching_regexp('directory','regexp')
0008 %
0009 % IN:
0010 %     datadir   directory to look at   e.g. '.'
0011 %     regexp    regular expression     e.g. '.m$e4' ($ signals the end of the filename)
0012 %
0013 %
0014 %
0015 % OUT: files    cell of matching file names
0016 %
0017 %
0018 % created by Salomon Eliasson
0019 % $Id$
0020 
0021 
0022 assert(~isempty(dir(datadir)),['atmlab:' mfilename ':BadInput'],...
0023     'Directory: %s\nDoes not exist',datadir)
0024 
0025 %replace tildas as this doesn't work with the system command
0026 datadir = [strrep(datadir(1),'~',getenv('HOME')) datadir(2:end)];
0027 
0028 % MAKE a list of files using UNIX find (regular files only)
0029 command = sprintf('find ''%s'' -type f',datadir);
0030 files = exec_system_cmd(command,gmtlab('VERBOSITY'));
0031 
0032 % use \n for one file per cell element from string output
0033 files = regexp(files{1},'\n','split');
0034 
0035 % Apply the regular expression rule to filter out unwanted files
0036 files = files(~cellfun('isempty',regexp(files,regularexp)));

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005