Next: Subfunctions, Up: Function Files [Contents][Index]

#### 11.9.1 Manipulating the Load Path

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 `path` function without any input or output arguments.

It is possible to add or remove directories to or from the load path using `addpath` and `rmpath`. As an example, the following code adds ‘`~/Octave`’ to the load path.

    addpath ("~/Octave")

After this the directory ‘`~/Octave`’ will be searched for functions.

Built-in Function: addpath (dir1, …)
Built-in Function: addpath (dir1, …, option)

  Add named directories to the function search path. If option is `"-begin"` or 0 (the default), prepend the directory name to the current path. If option is `"-end"` or 1, append the directory name to the current path. Directories added to the path must exist.

  In addition to accepting individual directory arguments, lists of directory names separated by `pathsep` are also accepted. For example:

      addpath ("dir1:/dir2:~/dir3")

  See also: path, rmpath, genpath, pathdef, savepath, pathsep.

Built-in Function: genpath (dir)
Built-in Function: genpath (dir, skip, …)

  Return a path constructed from dir and all its subdirectories. If additional string parameters are given, the resulting path will exclude directories with those names.

Built-in Function: rmpath (dir1, …)

  Remove dir1, … from the current function search path.

  In addition to accepting individual directory arguments, lists of directory names separated by `pathsep` are also accepted. For example:

      rmpath ("dir1:/dir2:~/dir3")

  See also: path, addpath, genpath, pathdef, savepath, pathsep.

Function File: savepath ()
Function File: savepath (file)
Function File: status = savepath (…)

  Save the unique portion of the current function search path that is not set during Octave’s initialization process to file. If file is omitted, `~/.octaverc` is used. If successful, `savepath` returns 0.

  See also: path, addpath, rmpath, genpath, pathdef.

Built-in Function: path (…)

  Modify or display Octave’s load path.

  If nargin and nargout are zero, display the elements of Octave’s load path in an easy to read format.

  If nargin is zero and nargout is greater than zero, return the current load path.

  If nargin is greater than zero, concatenate the arguments, separating them with `pathsep`. Set the internal search path to the result and return it.

  No checks are made for duplicate elements.

  See also: addpath, rmpath, genpath, pathdef, savepath, pathsep.

Function File: val = pathdef ()

  Return the default path for Octave. The path information is extracted from one of three sources. The possible sources, in order of preference, are:

  1. `~/.octaverc`
  2. `<octave-home>/…/<version>/m/startup/octaverc`
  3. Octave’s path prior to changes by any octaverc.

  See also: path, addpath, rmpath, genpath, savepath.

Built-in Function: val = pathsep ()
Built-in Function: old_val = pathsep (new_val)

  Query or set the character used to separate directories in a path.

  See also: filesep.

Built-in Function: rehash ()

  Reinitialize Octave’s load path directory cache.

Built-in Function: file_in_loadpath (file)
Built-in Function: file_in_loadpath (file, "all")

  Return the absolute name of file if it can be found in the list of directories specified by `path`. If no file is found, return an empty character string.

  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.

  If the second optional argument `"all"` 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.

  See also: file_in_path, find_dir_in_path, path.

Built-in Function: restoredefaultpath (…)

  Restore Octave’s path to its initial state at startup.

  See also: path, addpath, rmpath, genpath, pathdef, savepath, pathsep.

Built-in Function: command_line_path (…)

  Return the command line path variable.

  See also: path, addpath, rmpath, genpath, pathdef, savepath, pathsep.

Built-in Function: find_dir_in_path (dir)
Built-in Function: find_dir_in_path (dir, "all")

  Return the full name of the path element matching dir. The match is performed at the end of each path element. For example, if dir is `"foo/bar"`, it matches the path element `"/some/dir/foo/bar"`, but not `"/some/dir/foo/bar/baz"` `"/some/dir/allfoo/bar"`.

  The second argument is optional. If it is supplied, return a cell array containing all name matches rather than just the first.

  See also: file_in_path, file_in_loadpath, path.

Next: Subfunctions, Up: Function Files [Contents][Index]