function list(pattern, goUp)
%--------------------------------------------------------------------------------
% find files containing "pattern" in all directories and subdirectoris
% starting from a current dir
%
% Input(s): 	pattern	- file pattern (optional - if no pattern is specified, 
%			  all files will be listed)
%		goUp 	- flag (internal, do not use)
% Output(s):	none
% Usage:	list('.mp3')
%
% Last modified 25.12.01
% Copyright (c) 2001 Igor Kagan					 
% kigor@tx.technion.ac.il
% http://igoresha.virtualave.net
%--------------------------------------------------------------------------------

global nfiles ndirs basedir

if nargin < 1,
	pattern = '*.*';
end

if nargin < 2,

	% add to path
      	curdir = cd;
      	matlabpath = path;
      	if isempty(findstr(lower(matlabpath),lower(curdir))),
        	path(matlabpath,curdir);
      	end;

	% define startup parameters
	basedir = pwd;
	goUp	= 0;
	nfiles	= 0;
	ndirs	= 0;  % first is root (base) dir
end

% get current dir listing
d = dir;
ndirs = ndirs + 1;

if d(1).name=='.'
	d = d(3:length(d));
end

[t,ind]=sort(cat(1,d.isdir));
d = d(ind);

patternfound = 0;

for i=1:size(d,1),
	if d(i).isdir,
		cd(d(i).name);
		list(pattern,1);
	else
		if ~isempty(findstr(d(i).name,pattern)) | pattern=='*.*',
			if ~patternfound 
				disp([' [\ ',pwd,' \] ']);
				patternfound = 1;
			end

			disp(d(i).name);
			nfiles = nfiles + 1;
	     
		end			       
	end

end

if patternfound
	disp(' ')
end

if (goUp),
	cd ..
else
	disp([num2str(nfiles),' files found in ', num2str(ndirs),' directories'])
	       
end
return


