time | calls | line |
---|
| | 1 | function oldpath = addpath(varargin)
|
| | 2 | %ADDPATH Add directory to search path.
|
| | 3 | % ADDPATH DIRNAME prepends the specified directory to the current
|
| | 4 | % matlabpath. Surround the DIRNAME in quotes if the name contains a
|
| | 5 | % space. If DIRNAME is a set of multiple directories separated by path
|
| | 6 | % separators, then each of the specified directories will be added.
|
| | 7 | %
|
| | 8 | % ADDPATH DIR1 DIR2 DIR3 ... prepends all the specified directories to
|
| | 9 | % the path.
|
| | 10 | %
|
| | 11 | % ADDPATH ... -END appends the specified directories.
|
| | 12 | % ADDPATH ... -BEGIN prepends the specified directories.
|
| | 13 | % ADDPATH ... -FROZEN disables directory change detection for directories
|
| | 14 | % being added and thereby conserves Windows change
|
| | 15 | % notification resources (Windows only).
|
| | 16 | %
|
| | 17 | % Use the functional form of ADDPATH, such as ADDPATH('dir1','dir2',...),
|
| | 18 | % when the directory specification is stored in a string.
|
| | 19 | %
|
| | 20 | % P = ADDPATH(...) returns the path prior to adding the specified paths.
|
| | 21 | %
|
| | 22 | % Examples
|
| | 23 | % addpath c:\matlab\work
|
| | 24 | % addpath /home/user/matlab
|
| | 25 | % addpath /home/user/matlab:/home/user/matlab/test:
|
| | 26 | % addpath /home/user/matlab /home/user/matlab/test
|
| | 27 | %
|
| | 28 | % See also RMPATH, PATHTOOL, PATH, SAVEPATH, USERPATH, GENPATH, REHASH.
|
| | 29 |
|
| | 30 | % Copyright 1984-2014 The MathWorks, Inc.
|
| | 31 |
|
| | 32 | % Number of input arguments
|
| 2 | 33 | n = nargin;
|
| 2 | 34 | narginchk(1,Inf);
|
| | 35 |
|
| 2 | 36 | if nargout>0
|
| | 37 | oldpath = path;
|
| | 38 | end
|
| | 39 |
|
| 2 | 40 | append = -1;
|
| 2 | 41 | freeze = 0;
|
| 2 | 42 | args = varargin;
|
| | 43 |
|
| 2 | 44 | while (n > 1)
|
| | 45 | last = args{n};
|
| | 46 | % Append or prepend to the existing path
|
| | 47 | if isequal(last,1) || strcmpi(last,'-end')
|
| | 48 | if (append < 0), append = 1; end;
|
| | 49 | n = n - 1;
|
| | 50 | elseif isequal(last,0) || strcmpi(last,'-begin')
|
| | 51 | if (append < 0), append = 0; end;
|
| | 52 | n = n - 1;
|
| | 53 | elseif strcmpi(last,'-frozen')
|
| | 54 | if ispc, freeze = 1; end
|
| | 55 | n = n - 1;
|
| | 56 | else
|
| | 57 | break;
|
| | 58 | end
|
| | 59 | end
|
| 2 | 60 | if (append < 0), append = 0; end
|
| | 61 |
|
| | 62 | % Check, trim, and concatenate the input strings
|
0.01 | 2 | 63 | p = catdirs(varargin{1:n});
|
| | 64 |
|
| | 65 | % If p is empty then return
|
| 2 | 66 | if isempty(p)
|
| | 67 | return;
|
| | 68 | end
|
| | 69 |
|
| | 70 | % See whether frozen is desired, where the state is not already set frozen
|
| 2 | 71 | if freeze
|
| | 72 | oldfreeze = system_dependent('DirsAddedFreeze');
|
| | 73 | % Check whether old unfrozen state needs to be restored
|
| | 74 | if ~isempty(strfind(oldfreeze,'unfrozen'))
|
| | 75 | %Use the onCleanup object to automatically restore old state at
|
| | 76 | %exit or error.
|
| | 77 | cleanUp = onCleanup(@()system_dependent('DirsAddedUnfreeze'));
|
| | 78 | end
|
| | 79 | end
|
| | 80 |
|
| | 81 | % Append or prepend the new path
|
| 2 | 82 | mp = matlabpath;
|
| 2 | 83 | if append
|
| | 84 | path(mp, p);
|
| 2 | 85 | else
|
0.10 | 2 | 86 | path(p, mp);
|
| 2 | 87 | end
|
Other subfunctions in this file are not included in this listing.