<html lang="en"> <head> <title>Manipulating the Load Path - GNU Octave</title> <meta http-equiv="Content-Type" content="text/html"> <meta name="description" content="GNU Octave"> <meta name="generator" content="makeinfo 4.13"> <link title="Top" rel="start" href="index.html#Top"> <link rel="up" href="Function-Files.html#Function-Files" title="Function Files"> <link rel="next" href="Subfunctions.html#Subfunctions" title="Subfunctions"> <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> <meta http-equiv="Content-Style-Type" content="text/css"> <style type="text/css"><!-- pre.display { font-family:inherit } pre.format { font-family:inherit } pre.smalldisplay { font-family:inherit; font-size:smaller } pre.smallformat { font-family:inherit; font-size:smaller } pre.smallexample { font-size:smaller } pre.smalllisp { font-size:smaller } span.sc { font-variant:small-caps } span.roman { font-family:serif; font-weight:normal; } span.sansserif { font-family:sans-serif; font-weight:normal; } --></style> </head> <body> <div class="node"> <a name="Manipulating-the-Load-Path"></a> <p> Next: <a rel="next" accesskey="n" href="Subfunctions.html#Subfunctions">Subfunctions</a>, Up: <a rel="up" accesskey="u" href="Function-Files.html#Function-Files">Function Files</a> <hr> </div> <h4 class="subsection">11.8.1 Manipulating the Load Path</h4> <p>When a function is called, Octave searches a list of directories for a file that contains the function declaration. This list of directories is known as the load path. By default the load path contains a list of directories distributed with Octave plus the current working directory. To see your current load path call the <code>path</code> function without any input or output arguments. <p>It is possible to add or remove directories to or from the load path using <code>addpath</code> and <code>rmpath</code>. As an example, the following code adds ‘<samp><span class="samp">~/Octave</span></samp>’ to the load path. <pre class="example"> addpath("~/Octave") </pre> <p class="noindent">After this the directory ‘<samp><span class="samp">~/Octave</span></samp>’ will be searched for functions. <!-- addpath src/load-path.cc --> <p><a name="doc_002daddpath"></a> <div class="defun"> — Built-in Function: <b>addpath</b> (<var>dir1, <small class="dots">...</small></var>)<var><a name="index-addpath-762"></a></var><br> — Built-in Function: <b>addpath</b> (<var>dir1, <small class="dots">...</small>, option</var>)<var><a name="index-addpath-763"></a></var><br> <blockquote><p>Add <var>dir1</var>, <small class="dots">...</small> to the current function search path. If <var>option</var> is "-begin" or 0 (the default), prepend the directory name to the current path. If <var>option</var> is "-end" or 1, append the directory name to the current path. Directories added to the path must exist. <p>In addition to accepting individual directory arguments, lists of directory names separated by <code>pathsep</code> are also accepted. For example: <pre class="example"> addpath ("dir1:/dir2:~/dir3"); </pre> <!-- Texinfo @sp should work but in practice produces ugly results for HTML. --> <!-- A simple blank line produces the correct behavior. --> <!-- @sp 1 --> <p class="noindent"><strong>See also:</strong> <a href="doc_002dpath.html#doc_002dpath">path</a>, <a href="doc_002drmpath.html#doc_002drmpath">rmpath</a>, <a href="doc_002dgenpath.html#doc_002dgenpath">genpath</a>, <a href="doc_002dpathdef.html#doc_002dpathdef">pathdef</a>, <a href="doc_002dsavepath.html#doc_002dsavepath">savepath</a>, <a href="doc_002dpathsep.html#doc_002dpathsep">pathsep</a>. </p></blockquote></div> <!-- genpath src/load-path.cc --> <p><a name="doc_002dgenpath"></a> <div class="defun"> — Built-in Function: <b>genpath</b> (<var>dir</var>)<var><a name="index-genpath-764"></a></var><br> — Built-in Function: <b>genpath</b> (<var>dir, skip, <small class="dots">...</small></var>)<var><a name="index-genpath-765"></a></var><br> <blockquote><p>Return a path constructed from <var>dir</var> and all its subdirectories. If additional string parameters are given, the resulting path will exclude directories with those names. </p></blockquote></div> <!-- rmpath src/load-path.cc --> <p><a name="doc_002drmpath"></a> <div class="defun"> — Built-in Function: <b>rmpath</b> (<var>dir1, <small class="dots">...</small></var>)<var><a name="index-rmpath-766"></a></var><br> <blockquote><p>Remove <var>dir1</var>, <small class="dots">...</small> from the current function search path. <p>In addition to accepting individual directory arguments, lists of directory names separated by <code>pathsep</code> are also accepted. For example: <pre class="example"> rmpath ("dir1:/dir2:~/dir3"); </pre> <!-- Texinfo @sp should work but in practice produces ugly results for HTML. --> <!-- A simple blank line produces the correct behavior. --> <!-- @sp 1 --> <p class="noindent"><strong>See also:</strong> <a href="doc_002dpath.html#doc_002dpath">path</a>, <a href="doc_002daddpath.html#doc_002daddpath">addpath</a>, <a href="doc_002dgenpath.html#doc_002dgenpath">genpath</a>, <a href="doc_002dpathdef.html#doc_002dpathdef">pathdef</a>, <a href="doc_002dsavepath.html#doc_002dsavepath">savepath</a>, <a href="doc_002dpathsep.html#doc_002dpathsep">pathsep</a>. </p></blockquote></div> <!-- savepath scripts/path/savepath.m --> <p><a name="doc_002dsavepath"></a> <div class="defun"> — Function File: <b>savepath</b> (<var>file</var>)<var><a name="index-savepath-767"></a></var><br> <blockquote><p>Save the portion of the current function search path, that is not set during Octave's initialization process, to <var>file</var>. If <var>file</var> is omitted, <samp><span class="file">~/.octaverc</span></samp> is used. If successful, <code>savepath</code> returns 0. <!-- Texinfo @sp should work but in practice produces ugly results for HTML. --> <!-- A simple blank line produces the correct behavior. --> <!-- @sp 1 --> <p class="noindent"><strong>See also:</strong> <a href="doc_002dpath.html#doc_002dpath">path</a>, <a href="doc_002daddpath.html#doc_002daddpath">addpath</a>, <a href="doc_002drmpath.html#doc_002drmpath">rmpath</a>, <a href="doc_002dgenpath.html#doc_002dgenpath">genpath</a>, <a href="doc_002dpathdef.html#doc_002dpathdef">pathdef</a>, <a href="doc_002dpathsep.html#doc_002dpathsep">pathsep</a>. </p></blockquote></div> <!-- path src/load-path.cc --> <p><a name="doc_002dpath"></a> <div class="defun"> — Built-in Function: <b>path</b> (<var><small class="dots">...</small></var>)<var><a name="index-path-768"></a></var><br> <blockquote><p>Modify or display Octave's load path. <p>If <var>nargin</var> and <var>nargout</var> are zero, display the elements of Octave's load path in an easy to read format. <p>If <var>nargin</var> is zero and nargout is greater than zero, return the current load path. <p>If <var>nargin</var> is greater than zero, concatenate the arguments, separating them with <code>pathsep</code>. Set the internal search path to the result and return it. <p>No checks are made for duplicate elements. <!-- Texinfo @sp should work but in practice produces ugly results for HTML. --> <!-- A simple blank line produces the correct behavior. --> <!-- @sp 1 --> <p class="noindent"><strong>See also:</strong> <a href="doc_002daddpath.html#doc_002daddpath">addpath</a>, <a href="doc_002drmpath.html#doc_002drmpath">rmpath</a>, <a href="doc_002dgenpath.html#doc_002dgenpath">genpath</a>, <a href="doc_002dpathdef.html#doc_002dpathdef">pathdef</a>, <a href="doc_002dsavepath.html#doc_002dsavepath">savepath</a>, <a href="doc_002dpathsep.html#doc_002dpathsep">pathsep</a>. </p></blockquote></div> <!-- pathdef scripts/path/pathdef.m --> <p><a name="doc_002dpathdef"></a> <div class="defun"> — Function File: <var>val</var> = <b>pathdef</b> ()<var><a name="index-pathdef-769"></a></var><br> <blockquote><p>Return the default path for Octave. The path information is extracted from one of three sources. In order of preference, those are; <ol type=1 start=1> <li><samp><span class="file">~/.octaverc</span></samp> <li><samp><span class="file"><octave-home>/.../<version>/m/startup/octaverc</span></samp> <li>Octave's path prior to changes by any octaverc. </ol> <!-- Texinfo @sp should work but in practice produces ugly results for HTML. --> <!-- A simple blank line produces the correct behavior. --> <!-- @sp 1 --> <p class="noindent"><strong>See also:</strong> <a href="doc_002dpath.html#doc_002dpath">path</a>, <a href="doc_002daddpath.html#doc_002daddpath">addpath</a>, <a href="doc_002drmpath.html#doc_002drmpath">rmpath</a>, <a href="doc_002dgenpath.html#doc_002dgenpath">genpath</a>, <a href="doc_002dsavepath.html#doc_002dsavepath">savepath</a>, <a href="doc_002dpathsep.html#doc_002dpathsep">pathsep</a>. </p></blockquote></div> <!-- pathsep src/dirfns.cc --> <p><a name="doc_002dpathsep"></a> <div class="defun"> — Built-in Function: <var>val</var> = <b>pathsep</b> ()<var><a name="index-pathsep-770"></a></var><br> — Built-in Function: <var>old_val</var> = <b>pathsep</b> (<var>new_val</var>)<var><a name="index-pathsep-771"></a></var><br> <blockquote><p>Query or set the character used to separate directories in a path. <!-- Texinfo @sp should work but in practice produces ugly results for HTML. --> <!-- A simple blank line produces the correct behavior. --> <!-- @sp 1 --> <p class="noindent"><strong>See also:</strong> <a href="doc_002dfilesep.html#doc_002dfilesep">filesep</a>. </p></blockquote></div> <!-- rehash src/load-path.cc --> <p><a name="doc_002drehash"></a> <div class="defun"> — Built-in Function: <b>rehash</b> ()<var><a name="index-rehash-772"></a></var><br> <blockquote><p>Reinitialize Octave's load path directory cache. </p></blockquote></div> <!-- file_in_loadpath src/utils.cc --> <p><a name="doc_002dfile_005fin_005floadpath"></a> <div class="defun"> — Built-in Function: <b>file_in_loadpath</b> (<var>file</var>)<var><a name="index-file_005fin_005floadpath-773"></a></var><br> — Built-in Function: <b>file_in_loadpath</b> (<var>file, "all"</var>)<var><a name="index-file_005fin_005floadpath-774"></a></var><br> <blockquote> <p>Return the absolute name of <var>file</var> if it can be found in the list of directories specified by <code>path</code>. If no file is found, return an empty character string. <p>If the first argument is a cell array of strings, search each directory of the loadpath for element of the cell array and return the first that matches. <p>If the second optional argument <code>"all"</code> is supplied, return a cell array containing the list of all files that have the same name in the path. If no files are found, return an empty cell array. <!-- Texinfo @sp should work but in practice produces ugly results for HTML. --> <!-- A simple blank line produces the correct behavior. --> <!-- @sp 1 --> <p class="noindent"><strong>See also:</strong> <a href="doc_002dfile_005fin_005fpath.html#doc_002dfile_005fin_005fpath">file_in_path</a>, <a href="doc_002dpath.html#doc_002dpath">path</a>. </p></blockquote></div> <!-- restoredefaultpath src/load-path.cc --> <p><a name="doc_002drestoredefaultpath"></a> <div class="defun"> — Built-in Function: <b>restoredefaultpath</b> (<var><small class="dots">...</small></var>)<var><a name="index-restoredefaultpath-775"></a></var><br> <blockquote><p>Restore Octave's path to its initial state at startup. <!-- Texinfo @sp should work but in practice produces ugly results for HTML. --> <!-- A simple blank line produces the correct behavior. --> <!-- @sp 1 --> <p class="noindent"><strong>See also:</strong> <a href="doc_002dpath.html#doc_002dpath">path</a>, <a href="doc_002daddpath.html#doc_002daddpath">addpath</a>, <a href="doc_002drmpath.html#doc_002drmpath">rmpath</a>, <a href="doc_002dgenpath.html#doc_002dgenpath">genpath</a>, <a href="doc_002dpathdef.html#doc_002dpathdef">pathdef</a>, <a href="doc_002dsavepath.html#doc_002dsavepath">savepath</a>, <a href="doc_002dpathsep.html#doc_002dpathsep">pathsep</a>. </p></blockquote></div> <!-- command_line_path src/load-path.cc --> <p><a name="doc_002dcommand_005fline_005fpath"></a> <div class="defun"> — Built-in Function: <b>command_line_path</b> (<var><small class="dots">...</small></var>)<var><a name="index-command_005fline_005fpath-776"></a></var><br> <blockquote><p>Return the command line path variable. <!-- Texinfo @sp should work but in practice produces ugly results for HTML. --> <!-- A simple blank line produces the correct behavior. --> <!-- @sp 1 --> <p class="noindent"><strong>See also:</strong> <a href="doc_002dpath.html#doc_002dpath">path</a>, <a href="doc_002daddpath.html#doc_002daddpath">addpath</a>, <a href="doc_002drmpath.html#doc_002drmpath">rmpath</a>, <a href="doc_002dgenpath.html#doc_002dgenpath">genpath</a>, <a href="doc_002dpathdef.html#doc_002dpathdef">pathdef</a>, <a href="doc_002dsavepath.html#doc_002dsavepath">savepath</a>, <a href="doc_002dpathsep.html#doc_002dpathsep">pathsep</a>. </p></blockquote></div> <!-- find_dir_in_path src/utils.cc --> <p><a name="doc_002dfind_005fdir_005fin_005fpath"></a> <div class="defun"> — Built-in Function: <b>find_dir_in_path</b> (<var>dir</var>)<var><a name="index-find_005fdir_005fin_005fpath-777"></a></var><br> — Built-in Function: <b>find_dir_in_path</b> (<var>dir, "all"</var>)<var><a name="index-find_005fdir_005fin_005fpath-778"></a></var><br> <blockquote><p>Return the full name of the path element matching <var>dir</var>. The match is performed at the end of each path element. For example, if <var>dir</var> is <code>"foo/bar"</code>, it matches the path element <code>"/some/dir/foo/bar"</code>, but not <code>"/some/dir/foo/bar/baz"</code> or <code>"/some/dir/allfoo/bar"</code>. <p>The second argument is optional. If it is supplied, return a cell array containing all name matches rather than just the first. </p></blockquote></div> </body></html>