简体   繁体   English

如何在启动时更改Octave工作目录?

[英]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; 我花了很多时间搜索Octave wiki文档等,最终找到了一种在启动时更改Octave工作目录的方法; when typing system('set') at the Octave command prompt, it lists all environment variables, ia USERPROFILE=C:\\Users\\me . Octave命令提示符下键入system('set')时,它会列出所有环境变量,即USERPROFILE=C:\\Users\\me But I want the program to load C:\\Users\\me\\Octave instead. 但我想让程序加载C:\\Users\\me\\Octave

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 . 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. 它在每个Octave启动时更改环境变量USERPROFILE ,然后告诉程序将其用作工作目录。 Isn't there a way to permanently change USERPROFILE , maybe on the Windows command line? 有没有办法永久更改USERPROFILE ,可能在Windows命令行上?

Octave does not care where it starts and is not configured to start in any place. Octave并不关心它从哪里开始,也没有配置为在任何地方启动。 When you start Octave, its working directory will be whatever directory you were when you started it. 当你启动Octave时,它的工作目录将是你启动它时的目录。

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. 当您双击图标以启动应用程序(如Octave)时,您的系统需要在某处启动它。 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. 尝试右键单击Octave图标,然后在属性菜单中查找有关配置启动目录的信息。

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 . 但是,如果你对Octave应该如何工作的想法是它应该总是移动到一个特定的目录,那么我会像你现在一样使用.octaverc但我只会做cd ("...") ,没有需要设置USERPROFILE That will ensure that Octave always changes directory there, no matter how start Octave. 这将确保Octave始终在那里更改目录,无论如何启动Octave。

If you are using Octave Workbench, it's easy to change the directory using File Browser window by clicking on the wheel button and click "Set Browsing Directory", choose your respective directory and click ok. 如果您使用的是Octave Workbench,可以通过单击“滚轮”按钮并单击“设置浏览目录”,使用“文件浏览器”窗口轻松更改目录,选择相应的目录并单击“确定”。 This changes your current directory. 这会更改您当前的目录。 Can also be verified using pwd command. 也可以使用pwd命令验证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM