How to find the name of the file that is being edited?
Show older comments
Hi, I would like to write a Matlab script that performs an operation on the file that is being eddited (file that is displayed now in the editor window). To do so, I need to know the name of the file. I was looking all over the places and didn't find the solution. To be more specific, I looking for a solution like gcf() The reason I'm looking for such a solution is that I would like to do some analysis and processing on the eddited file like: Publish (without the Matlab option), save to... Thank you, Alecs
Accepted Answer
More Answers (2)
doc mfilename
will give you the name of the file currently executing.
I'm not aware of any function that will give you the names of all files currently open in the editor though if that is what you mean instead.
1 Comment
Alecsander Eitan
on 1 Sep 2015
Guillaume
on 1 Sep 2015
See Yair's site on how to access the editor. Accessing the name of the file being currently edited is one of the first example:
desktop = com.mathworks.mde.desk.MLDesktop.getInstance;
jEditor = desktop.getGroupContainer('Editor').getTopLevelAncestor;
jEditor.getTitle
Of course, as it relies on undocumented interfaces, there's no guarantee that it will work in future versions.
1 Comment
Alecsander Eitan
on 1 Sep 2015
Categories
Find more on File Operations 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!