Search code examples
windows-7octaveworking-directory

How to change Octave working directory at startup?


It took me a lot of searching on Octave wiki, documentation etc., to finally find a way to change Octave working directory at startup; when typing system('set') at the Octave command prompt, it lists all environment variables, i.a. USERPROFILE=C:\Users\me. But I want the program to load C:\Users\me\Octave instead.

A possible solution consists in adding the following lines

setenv("USERPROFILE", "C:\\Users\\me\\Octave");
cd(getenv("USERPROFILE"));

to C:\Octave\Octave-4.0.3\share\octave\4.0.3\m\startup\octaverc.

However, this appears a bit clumpsy to me. It changes the environment variable USERPROFILE at each Octave startup and then tells the program to use it as the working directory. Isn't there a way to permanently change USERPROFILE, maybe on the Windows command line?


Solution

  • Octave does not care where it starts and is not configured to start in any place. When you start Octave, its working directory will be whatever directory you were when you started it.

    This makes a lot more sense when you do things in the command line which I guess is not your case. When you double click on an icon to start an application, like Octave, your system needs to start it somewhere. How to configure this will be system-dependent. Try right click on your the Octave icon, and in the properties menu look for something about configuring the start directory.

    However, if your idea of how Octave should work is that it should always move to a specific directory, then I would use the .octaverc as you are now --- but I would just do cd ("..."), no need to set USERPROFILE. That will ensure that Octave always changes directory there, no matter how start Octave.