How to dissect a file path and keep extension Matlab

1 vue (au cours des 30 derniers jours)
Lucas S
Lucas S le 15 Avr 2019
Commenté : Lucas S le 15 Avr 2019
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 !

Réponse acceptée

Stephen23
Stephen23 le 15 Avr 2019
Modifié(e) : Stephen23 le 15 Avr 2019
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'

Plus de réponses (0)

Catégories

En savoir plus sur File Operations dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by