How to dissect a file path and keep extension Matlab

조회 수: 1 (최근 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'

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by