getlist_jd

PURPOSE ^

SYNOPSIS ^

function filenames = getlist_jd(filepath,filename)

DESCRIPTION ^

 This function gets the list of files of the format 'filename' in the
 directory 'filepath'. 'filename' is a standard file name that can contain
 the character '*' to account for any string.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function filenames = getlist_jd(filepath,filename)
0002 %
0003 % This function gets the list of files of the format 'filename' in the
0004 % directory 'filepath'. 'filename' is a standard file name that can contain
0005 % the character '*' to account for any string.
0006 %
0007 starloc = strfind(filename,'*');
0008 %
0009 if isempty(starloc),
0010     if exist([filepath,filename],'file'),
0011         filenames = {filename};
0012     else
0013         filenames = {};
0014     end
0015 else
0016     %
0017     filelist = dir(filepath);
0018     nfiles = length(filelist);
0019     filenames = cell(1,nfiles);
0020     istr = ones(1,nfiles);
0021     %
0022     for ifile = 1:length(filelist),
0023         filenames{ifile} = filelist(ifile).name;
0024     end
0025     %
0026     starloc = [0,starloc,length(filename) + 1];
0027     %
0028     for istar = 1:length(starloc)-1;
0029         %
0030         str = filename(starloc(istar)+1:starloc(istar+1)-1);
0031         %
0032         if isempty(str),
0033             continue
0034         end
0035         %
0036         nfiles = length(filenames);
0037         sel = true(1,nfiles);
0038         %
0039         for ifile = 1:nfiles,
0040             %
0041             istrloc = strfind(filenames{ifile}(istr(ifile):end),str);
0042             %
0043             if isempty(istrloc),
0044                 sel(ifile) = false;
0045                 continue
0046             else
0047                 istr(ifile) = istr(ifile)+(istrloc-1)+length(str);
0048             end
0049             %
0050             if istar == 1 && istrloc(1) ~= 1,% file starts differ
0051                 sel(ifile) = false;
0052             end
0053             %
0054             if istar == length(starloc)-1 && istr(ifile) <= length(filenames{ifile}),% file ends differ
0055                 sel(ifile) = false;
0056             end
0057             %
0058         end
0059         %
0060         filenames = filenames(sel);
0061         istr = istr(sel);
0062         %
0063     end           
0064 end
0065 %

Community support and wiki are available on Redmine. Last update: 18-Apr-2019.