Search code examples
windowspathoctave

How do you get your path in Octave (on Windows)?


I used addpath(pwd) to get my .m files working in my projects directory. When I close the window and start a new window, the path I just added is gone. But the files still run.

Is it in my path or not? How do I see the directories I have added to my path?

Also, . is the first entry I see from path. Does that mean I don't need to add any directories because it will always search the current directory first?

Thanks.


Solution

  • Basically, yes.

    You can add a directory to the search path using addpath(), but as you know, it only exists for the current session and is reset when you restart Octave. If you want a path to survive between sessions, add it to your octaverc, a script file that gets run whenever a new session gets started. Example path to octaverc file is:

    C:\Octave\3.2.4_gcc-4.4.0\share\octave\site\m\startup
    

    Since . is in your path by default, Octave will search your current directory for any function files that it needs. Using addpath(pwd) is somewhat useless if you're just going to stay in the same directory. However, there are some cases where it'd be useful, if for example you have a directory that contains your functions, and another one that has the data that you're working on: you could start in the functions directory, do addpath(pwd), and then cd to the data directory while still being able to use your functions.