Code covered by the BSD License  

Highlights from
locate

from locate by michael arant
A which command that also handles shadowed files and partial string matches for function names.

locate(fn,wild)
function [l] = locate(fn,wild)
% locate all copies of a file - advanced which
% [l] = locate(fn,wild)
%
% inputs  2 - 1 optional
% fn      file name                     class char
% wild    look for any partial match	class any - optional
%
% outputs 1 - 1 optional
% l       list of outputs               class cell
%
% michael arant - may 23, 2007
%
% ex.  locate plot, locate plot 1, l = locate('plot'), l = locate('plot',1)

if nargin == 0; help locate; error('I/O error'); end

% simple search?
if ~exist('wild','var')
	% is there a function?
	if isempty(which(fn))
		if nargout
			l = [];
		else
			disp('No functions found')
		end
	else
	% get occurances
		if nargout
			l = which(fn,'-all');
		else
			which(fn,'-all')
		end
	end
else
	% get partial matches
	% get all files in path
	w = what(''); ws = size(w,1); l = {};
	% evaluate each directory in the path for string match
	for ii = 1:ws
		% get the files in the directory
		temp = w(ii).m; temps = size(temp,1);
		% search for string matches
		for jj = 1:temps
			% wild card search
			if ~isempty(findstr(char(w(ii).m(jj)),fn))
				l = [l; cellstr([char(w(ii).path) filesep char(w(ii).m(jj))])];
			end
		end
	end
	% dump display if output not requested
	if ~nargout; for ii = 1:numel(l); fprintf('%s\n',l{ii}); end; clear l; end
end
return

Contact us at files@mathworks.com