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 Comment

But what if the user navigate to a completely different folder? Maybe not even on the same drive?

Sign in to comment.

 Accepted Answer

Stephen23
Stephen23 on 27 Jun 2017
Edited: Stephen23 on 23 Mar 2022
fp = uigetdir('./subfolder1/');
[~,name] = fileparts(fp)

3 Comments

change second line of text to:
[~name]=fileparts(filepath)

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Asked:

on 27 Jun 2017

Commented:

on 23 Mar 2022

Community Treasure Hunt

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

Start Hunting!