time | Calls | line |
---|
| | 1 | function p = genpath(d)
|
| | 2 | %GENPATH Generate recursive toolbox path.
|
| | 3 | % P = GENPATH returns a character vector containing a path name
|
| | 4 | % that includes all the folders and subfolders below MATLABROOT/toolbox,
|
| | 5 | % including empty subfolders.
|
| | 6 | %
|
| | 7 | % P = GENPATH(FOLDERNAME) returns a character vector containing a path
|
| | 8 | % name that includes FOLDERNAME and all subfolders of FOLDERNAME,
|
| | 9 | % including empty subfolders.
|
| | 10 | %
|
| | 11 | % NOTE 1: GENPATH will not exactly recreate the original MATLAB path.
|
| | 12 | %
|
| | 13 | % NOTE 2: GENPATH only includes subfolders allowed on the MATLAB
|
| | 14 | % path.
|
| | 15 | %
|
| | 16 | % See also PATH, ADDPATH, RMPATH, SAVEPATH.
|
| | 17 |
|
| | 18 | % Copyright 1984-2017 The MathWorks, Inc.
|
| | 19 | %------------------------------------------------------------------------------
|
| | 20 |
|
| | 21 | % String Adoption
|
< 0.001 | 957 | 22 | if nargin > 0
|
< 0.001 | 957 | 23 | d = convertStringsToChars(d);
|
< 0.001 | 957 | 24 | end
|
| | 25 |
|
< 0.001 | 957 | 26 | if nargin==0,
|
| | 27 | p = genpath(fullfile(matlabroot,'toolbox'));
|
| | 28 | if length(p) > 1, p(end) = []; end % Remove trailing pathsep
|
| | 29 | return
|
| | 30 | end
|
| | 31 |
|
| | 32 | % initialise variables
|
< 0.001 | 957 | 33 | classsep = '@'; % qualifier for overloaded class directories
|
< 0.001 | 957 | 34 | packagesep = '+'; % qualifier for overloaded package directories
|
< 0.001 | 957 | 35 | p = ''; % path to be returned
|
| | 36 |
|
| | 37 | % Generate path based on given root directory
|
0.613 | 957 | 38 | files = dir(d);
|
< 0.001 | 957 | 39 | if isempty(files)
|
| | 40 | return
|
| | 41 | end
|
| | 42 |
|
| | 43 | % Add d to the path even if it is empty.
|
0.037 | 957 | 44 | p = [p d pathsep];
|
| | 45 |
|
| | 46 | % set logical vector for subdirectory entries in d
|
0.041 | 957 | 47 | isdir = logical(cat(1,files.isdir));
|
| | 48 | %
|
| | 49 | % Recursively descend through directories which are neither
|
| | 50 | % private nor "class" directories.
|
| | 51 | %
|
0.011 | 957 | 52 | dirs = files(isdir); % select only directory entries from the current listing
|
| | 53 |
|
< 0.001 | 957 | 54 | for i=1:length(dirs)
|
0.009 | 2868 | 55 | dirname = dirs(i).name;
|
0.015 | 2868 | 56 | if ~strcmp( dirname,'.') && ...
|
| 1911 | 57 | ~strcmp( dirname,'..') && ...
|
| 954 | 58 | ~strncmp( dirname,classsep,1) && ...
|
| 954 | 59 | ~strncmp( dirname,packagesep,1) && ...
|
| 954 | 60 | ~strcmp( dirname,'private')
|
0.174 | 954 | 61 | p = [p genpath(fullfile(d,dirname))]; % recursive calling of this function.
|
< 0.001 | 954 | 62 | end
|
0.013 | 2868 | 63 | end
|
Other subfunctions in this file are not included in this listing.