Is there a function that retrieves the filename of the current script?
112 views (last 30 days)
Show older comments
Tobin Fricke
on 20 Jun 2011
Commented: Chris Jennings
on 24 Oct 2022
Is there a way to, from a .m file, determine the filename (including directory path) of that .m file?
0 Comments
Accepted Answer
Walter Roberson
on 20 Jun 2011
S = dbstack();
S(1).file
You might have to use the -completenames option.
More Answers (3)
Eric LePage
on 23 Oct 2019
I'd appreciate a qualification, because what I get for R2019b is not very helpful; it certainly isn't the name of the currently running mfile. Thanks.
P = mfilename
P =
'LiveEditorEvaluationHelperESectionEval67edf31d'
or
S = dbstack();
>> S(1).file
ans =
'LiveEditorEvaluationHelperESectionEval67edf31d.mlx'
8 Comments
Martin Koch
on 23 Oct 2022
Path.this
and the parent directory with
Path.here
Use the string method to convert to a string if needed:
Path.this.string
Disclaimer: I'm the author.
0 Comments
See Also
Categories
Find more on Environment and Settings in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!