Filter löschen
Filter löschen

How to get only foldername with uigetdir

94 Ansichten (letzte 30 Tage)
Jonas K
Jonas K am 27 Jun. 2017
Kommentiert: Stephen23 am 23 Mär. 2022
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 Kommentar
Guillaume
Guillaume am 27 Jun. 2017
But what if the user navigate to a completely different folder? Maybe not even on the same drive?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Stephen23
Stephen23 am 27 Jun. 2017
Bearbeitet: Stephen23 am 23 Mär. 2022
fp = uigetdir('./subfolder1/');
[~,name] = fileparts(fp)
  3 Kommentare
Carl Hopkins
Carl Hopkins am 23 Mär. 2022
change second line of text to:
[~name]=fileparts(filepath)
Stephen23
Stephen23 am 23 Mär. 2022
@Carl Hopkins: fixed, thank you.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by