
How can I find the directory containing my compiled application?
51 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
MathWorks Support Team
am 12 Dez. 2012
Bearbeitet: MathWorks Support Team
am 16 Okt. 2024
How can I programmatically determine the directory containing my compiled application created with MATLAB Compiler (e.g., the .exe file on Windows)?
I am looking for a function similar to 'ctfroot' which returns the directory where the contents of the .exe file are extracted to.
Akzeptierte Antwort
MathWorks Support Team
am 18 Okt. 2024
Bearbeitet: MathWorks Support Team
am 16 Okt. 2024
It is possible to use the 'pwd' for this, as it returns the current working directory:
However, it is important to understand that the working directory of the executable is determined by the directory from which it is executed.
Using Shortcuts:
When launching a compiled application via a Windows shortcut, the current working directory is determined by the "Start In" property. For the 'pwd' command to function correctly, users must update this field in the shortcut's properties.
IMPORTANT NOTE: For desktop shortcuts created during the application installation process, the "Start In" property is empty. If the user launches the application by double-clicking this shortcut, 'pwd' will return the Desktop directory, not the .exe file's directory.
To fix this, adjust the "Start In" field to match the parent directory of the executable. For instance, if the "Target" is:
"C:\Program Files\appname\application\appname.exe"
Then set the "Start In" directory to:
"C:\Program Files\appname\application\"
This is shown in the screenshot below:

Using Windows Command Prompt or PowerShell:
When running the .exe from the directory where it's located:
C:\Program Files\appname\application>.\appname.exe
Then 'pwd' will be "C:\Program Files\appname\application". This will no longer work when calling the .exe from a different folder:
C:\Program Files\appname\application>cd C:\
C:\>"C:\Program Files\appname\application\appname.exe"
In this case, 'pwd' will be "C:\".
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Introduction to Installation and Licensing finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!