mfilename not predictable value return

5 ビュー (過去 30 日間)
Michele
Michele 2025 年 2 月 18 日
コメント済み: Michele 2025 年 2 月 18 日
I'm experiencing a strange behaviour when using mfilename function.
I compiled a script (myScript.m) that use mfilename into an executable (myScript.exe) and running it from a specific folder (C:\Users\username\Desktop\appfolder\).
I tought mfilename returned the binary full path but this's not true... i.e. running myScript.exe from the above folder and printing the value returned by mfilename I got:
C:\Users\username\AppData\Local\Temp\username\mcrCache9.7\myScriptN\myScriptT\myScript
Where myScriptN, myScriptT are temporary subfolders.
This path cannot be used to locate anything local or relative to to the binary folder.
Is there a function that can return the correct path when the script is executed compiled.
BTW the same issue is found also when script are compiled into DLL or .NET assemblies.
  2 件のコメント
Stephen23
Stephen23 2025 年 2 月 18 日
編集済み: Stephen23 2025 年 2 月 18 日
Cross platform:
[status, result] = system('cd');
currentPath = strtrim(result);
.NET:
NET.addAssembly('System.Runtime.InteropServices');
exePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
Michele
Michele 2025 年 2 月 18 日
also:
currentPath = pwd

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeIntroduction to Installation and Licensing についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by