How to get only foldername with uigetdir

Hello, I want to select a folder (would be subfolder2 in my example) and use its name as a string. The problem is that not only the foldername but the whole location is the output of uigetdir().
name = uigetdir('./subfolder1/');
Is there a simple function to just get the name of the selected folder?
Cheers, J

1 commentaire

Guillaume
Guillaume le 27 Juin 2017
But what if the user navigate to a completely different folder? Maybe not even on the same drive?

Connectez-vous pour commenter.

 Réponse acceptée

Stephen23
Stephen23 le 27 Juin 2017
Modifié(e) : Stephen23 le 23 Mar 2022
fp = uigetdir('./subfolder1/');
[~,name] = fileparts(fp)

3 commentaires

Jonas K
Jonas K le 27 Juin 2017
thanks!
Carl Hopkins
Carl Hopkins le 23 Mar 2022
change second line of text to:
[~name]=fileparts(filepath)
Stephen23
Stephen23 le 23 Mar 2022
@Carl Hopkins: fixed, thank you.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by