Find out file extension of a file from within the file.

40 ビュー (過去 30 日間)
Sasquatch
Sasquatch 2014 年 12 月 11 日
コメント済み: Sasquatch 2014 年 12 月 11 日
I have a build I want to give someone that contain protected models and I have a script that I also want to protect. Right now I have a parameter being passed in to say which library I want to ready from, but I don't like that. Is there any way that I can see if the file that is being run is a .m or a .p? If I can do that then I can base my choice on that. I tried using mfilename and it didn't work and I tried:
a = mfilename('fullpath');
[~,~,ext] = fileparts(a);
but that didn't work either. I don't want to use dir, since I'll have both versions on my computer. Is there anything I can do to get the file extension of the file that I run?

採用された回答

Sean de Wolski
Sean de Wolski 2014 年 12 月 11 日
編集済み: Sean de Wolski 2014 年 12 月 11 日
You could fileparts the output from which.
[~,~,ext] = fileparts(which(mfilename))
  1 件のコメント
Sasquatch
Sasquatch 2014 年 12 月 11 日
You have wisdom that one strives for! Thanks!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by