FILELISTING = ML_LS( PATTERN ) Returns file listing of wildcard PATTERN (e.g. '*.jpg'). FILELISTING is a cell array of strings of filenames without path. the listing is sorted by name alphabetically
0001 function [allfiles, patternnum] = ml_ls( patterns ) 0002 % FILELISTING = ML_LS( PATTERN ) Returns file listing of wildcard PATTERN (e.g. '*.jpg'). 0003 % FILELISTING is a cell array of strings of filenames without path. 0004 % the listing is sorted by name alphabetically 0005 % 0006 0007 % 8/11/13 G. Johnson - modified such that pattern can be a string, or cell 0008 % array of strings, in case of the need for multiple 0009 % source directories 0010 % 0011 % Copyright (C) 2006-2013 Murphy Lab 0012 % Lane Center for Computational Biology 0013 % School of Computer Science 0014 % Carnegie Mellon University 0015 % 0016 % This program is free software; you can redistribute it and/or modify 0017 % it under the terms of the GNU General Public License as published 0018 % by the Free Software Foundation; either version 2 of the License, 0019 % or (at your option) any later version. 0020 % 0021 % This program is distributed in the hope that it will be useful, but 0022 % WITHOUT ANY WARRANTY; without even the implied warranty of 0023 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0024 % General Public License for more details. 0025 % 0026 % You should have received a copy of the GNU General Public License 0027 % along with this program; if not, write to the Free Software 0028 % Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 0029 % 02110-1301, USA. 0030 % 0031 % For additional information visit http://murphylab.web.cmu.edu or 0032 % send email to murphy@cmu.edu 0033 0034 if ~iscell(patterns) 0035 patterns = {patterns}; 0036 end 0037 0038 allfiles = cell(length(patterns),1); 0039 0040 %hidden option to the user 0041 option = 1; 0042 0043 if option == 1 0044 for c = 1:length(patterns) 0045 try 0046 files = {}; 0047 list = ls( patterns{c} ); 0048 rows = strread( list, '%s', 'delimiter', ' '); 0049 %rows = strread( list, '%s', 'delimiter', sprintf('\n')); 0050 for i=1:1:length(rows) 0051 temp = {}; 0052 temp = strread( rows{i},'%s','delimiter','\t'); 0053 for j=1:1:length(temp) 0054 if ~isempty(temp{j}) 0055 files{length(files)+1} = temp{j}; 0056 end 0057 end 0058 end 0059 catch 0060 files = {}; 0061 end 0062 0063 %D. Sullivan 6/20/13 - added natural sorting 0064 files = sort_nat( files ); 0065 allfiles{c} = files; 0066 patternnum{c} = ones(1,length(files))*c; 0067 end 0068 0069 allfiles = [allfiles{:}]; 0070 patternnum = [patternnum{:}]; 0071 else for c = 1:length(patterns) 0072 try 0073 files = {}; 0074 list = ls( patterns{c} ); 0075 rows = strread( list, '%s', 'delimiter', ' '); 0076 %rows = strread( list, '%s', 'delimiter', sprintf('\n')); 0077 for i=1:1:length(rows) 0078 temp = {}; 0079 temp = strread( rows{i},'%s','delimiter','\t'); 0080 for j=1:1:length(temp) 0081 if ~isempty(temp{j}) 0082 files{length(files)+1} = temp{j}; 0083 end 0084 end 0085 end 0086 catch 0087 files = {}; 0088 end 0089 0090 %D. Sullivan 6/20/13 - added natural sorting 0091 files = sort_nat( files ); 0092 allfiles{c} = files; 0093 patternnum{c} = ones(1,length(files))*c; 0094 end 0095 0096 allfiles = [allfiles{:}]; 0097 patternnum = [patternnum{:}]; 0098 end 0099 end