function [flist, pathname] = getfiles(filefilter) % GETFILE Retrieve the filelist and the pathname. % % [FILELIST, PATHNAME] = GETFILE('filterSpec') % % The filterSpec parameter determines the files to be retrieve. % Default is '*.mat'. % For example '/usr/mfile/*.m' retrieves all the MATLAB M-files % in the directory /usr/mfile % The output parameter FILELIST is a matrix containing the name of the % files found in the path. The number of rows of the matrix correspond % to the number of files found, the number of columns is the length % of the longest filename found. The sorter filenames are filled % with zeros. % The output parameter PATHNAME is a string containing the path of % the files found. % % See also UIGETFILE, UIPUTFILE. % % Copyright (c) 1995 by Claudio Rivetti and Mark Young % claudio@alice.uoregon.edu, mark@alice.uoregon.edu % if nargin > 1 error('Too many input arguments'); end if nargin < 1 filefilter = '*.mat'; end command=['ls -1 ' filefilter]; [ok,list]=unix(command); if ok~=0 error(['Error executing command: ' command]); end flist=[]; while 1 [string,list]=strtok(list, setstr(10)); if isempty(string), break, end len = length(string); p=max(find(string=='/')); if isempty(p), p=0; end flist=str2mat(flist,string(p+1:len)); end p=max(find(filefilter=='/')); if ~isempty(flist) flist=flist(2:size(flist,1),:); if isempty(p) pathname=[pwd '/']; else pathname=filefilter(1:p); end end return