[英]How do I get the current script path in GNU Octave?
In GNU Octave, how do I get the path to the directory the script is stored in?在 GNU Octave 中,如何获取脚本存储目录的路径? I would like this to work regardless of the current directory.无论当前目录如何,我都希望它可以工作。
This works for both Octave and Matlab:这适用于 Octave 和 Matlab:
file_path = fileparts(mfilename('fullpath'));
The function mfilename
returns the name of the script it is called from.函数mfilename
返回调用它的脚本的名称。 When called with 'fullpath'
, it returns the full path to that file (including the file name and extension).当使用'fullpath'
调用时,它返回该文件的完整路径(包括文件名和扩展名)。fileparts
extracts the path to the containing folder.fileparts
提取包含文件夹的路径。
Note that this will return an empty string if called from the console.请注意,如果从控制台调用,这将返回一个空字符串。
如果您想知道另一个脚本的位置,您也可以尝试使用以下命令:
which("myScript");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.