How to dissect a file path and keep extension Matlab

2 ビュー (過去 30 日間)
Lucas S
Lucas S 2019 年 4 月 15 日
コメント済み: Lucas S 2019 年 4 月 15 日
I have my file path in a string :
path = 'D:\Users\Documents\MATLAB\capella_to_matlab.txt'
How can i put only the extension in an other string (Not just for this file but for any file i put in path variable) for example :
extension = '.txt'
Thanks for helping !

採用された回答

Stephen23
Stephen23 2019 年 4 月 15 日
編集済み: Stephen23 2019 年 4 月 15 日
Do NOT use path as a variable name! This shadows the important inbuilt path function.
To get the file extension use fileparts:
>> P ='D:\Users\Documents\MATLAB\capella_to_matlab.txt';
>> [~,~,E] = fileparts(P)
E = '.txt'
  1 件のコメント
Lucas S
Lucas S 2019 年 4 月 15 日
Thank you very much !

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

その他の回答 (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