No BSD License  

Highlights from
MUnit: a unit testing framework in Matlab

MUnit: a unit testing framework in Matlab

by

 

05 Jun 2006 (Updated )

A complete unit testing framework in Matlab

dirfiles(pattern,fullpath)
function filenames = dirfiles(pattern,fullpath)
% DIRFILES  Lists a set of filenames
%
%  This function lists a set of filenames without other infos, the result
% is packed ina string cell. This function uses DIR, so take a look to
% 'help dir'!!!
%
%  Params
%  ------
% IN:
%  pattern      = The path to be listed (def=pwd)
%  fullpath     = A logical that says if the fullpath must be the output (def=true)
% OUT:
%  filenames    = A string cell array containing the filenames
%
%  Pre
%  ---
% -  The given path is correct.
%
%  Post
%  ----
% -  The files contained at the specified path is listed.
%
%  SeeAlso
%  -------
% dir
%
%  Examples
%  --------
%   Listing the contents of the actual dir:
% >> dirfiles

% Check the input args:
if nargin<1 pattern = pwd; end
if nargin<2 fullpath = true; end

% Generating the full path:
if isdir(pattern)
    path = pattern;
else
    [path,name,ext] = fileparts(pattern);
end
if strcmp(path,'')
    path = pwd;
else
    oldpath=pwd; cd(path);
    path=pwd; cd(oldpath);
end

% Obtaining data
data = dir(pattern);

% Collect data
files = {};
for ind=1:size(data,1)
    % Require fullpath?
    if fullpath
        files = {files{:},[path filesep data(ind).name]};
    else
        files = {files{:},data(ind).name};
    end
end

% Output
if nargout<1
    for ind=1:size(files,2)
        disp(files{ind});
    end
else
    filenames = files;
end

Contact us