To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Revision:

root / mygenpath.m

History | View | Annotate | Download (1.89 KB)

1 0:4182672fd6f8 Chris
function p = mygenpath(d,varargin)
2
%GENPATH Generate recursive toolbox path.
3
%   P = GENPATH returns a new path string by adding
4
%   all the subdirectories of MATLABROOT/toolbox, including empty
5
%   subdirectories.
6
%
7
%   P = GENPATH(D) returns a path string starting in D, plus, recursively, all
8
%   the subdirectories of D, including empty subdirectories.
9
%
10
%   NOTE: GENPATH will not exactly recreate the original MATLAB path.
11
%
12
%   See also PATH, ADDPATH, RMPATH, SAVEPATH.
13
14
%   Copyright 1984-2006 The MathWorks, Inc.
15
%   $Revision: 1.13.4.4 $ $Date: 2006/10/14 12:24:02 $
16
%------------------------------------------------------------------------------
17
18
if nargin==0,
19
  p = genpath(fullfile(matlabroot,'toolbox'));
20
  if length(p) > 1, p(end) = []; end % Remove trailing pathsep
21
  return
22
end
23
if nargin==1
24
  pat = 'imporobablepatternthisis';
25
else
26
  pat = varargin{1};
27
end
28
% initialise variables
29
methodsep = '@';  % qualifier for overloaded method directories
30
p = '';           % path to be returned
31
32
% Generate path based on given root directory
33
files = dir(d);
34
if isempty(files)
35
  return
36
end
37
38
% Add d to the path even if it is empty.
39
p = [p d pathsep];
40
41
% set logical vector for subdirectory entries in d
42
isdir = logical(cat(1,files.isdir));
43
%
44
% Recursively descend through directories which are neither
45
% private nor "class" directories.
46
%
47
dirs = files(isdir); % select only directory entries from the current listing
48
49
for i=1:length(dirs)
50
   dirname = dirs(i).name;
51
   if    ~strcmp( dirname,'.')          && ...
52
         ~strcmp( dirname,'..')         && ...
53
         ~strncmp( dirname,methodsep,1) && ...
54
         ~strcmp( dirname,'private')    && ...
55
         isempty(regexp(dirname,'svn','ONCE')) && ...
56
         isempty(regexp(dirname, pat,'ONCE'))
57
      p = [p genpath(fullfile(d,dirname))]; % recursive calling of this function.
58
   end
59
end
60
61
%------------------------------------------------------------------------------