能否通过MATLAB命令行查看具体程序的安装路径? 或者我可以找到已注册程序的路径(相当于 Windows reg)吗?
最佳答案
这不会 100% 可靠,但大多数时候都会得到正确的答案:
function p = findOnSystemPath(f)
p = '';
path = getenv('path');
dirs = regexp(path,pathsep,'split');
for iDirs = 1:numel(dirs)
tp = fullfile(dirs{iDirs},f);
if exist(p,'file')
p = tp;
break
end
end
使用示例:
>> findOnSystemPath('runemacs.exe')
ans =
C:\Program Files (x86)\emacs\bin\runemacs.exe
根据您的操作系统,您也许可以直接从系统获取此信息:
which
可在 Unix 系统和 Windows 系统上使用 Cygwin安装:
>> [~,p] = system(sprintf('which "%s"',f))
p =
C:/Program Files (x86)/emacs-mw-a/bin/runemacs.exe
where
可在 Windows 2003 and later 上找到:
>> [~,p] = system(sprintf('where "%s"',f))
p =
C:\Program Files (x86)\emacs-mw-a\bin\runemacs.exe
在某些情况下,您可以使用 winqueryreg 从注册表中提取此信息。 ,例如:
>> notepadEdit = winqueryreg('HKEY_CLASSES_ROOT','Applications\notepad.exe\shell\edit\command')
notepadEdit =
C:\Windows\system32\NOTEPAD.EXE %1
关于matlab - 从 MATLAB 中查找已安装程序的路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5818545/