Populate listbox with only directories?

2 Ansichten (letzte 30 Tage)
Ibro Tutic
Ibro Tutic am 16 Jun. 2017
Beantwortet: Adam am 16 Jun. 2017
I am trying to populate a listbox with only the folder names (directories) in a folder. The code below does that, but there are some weird '.' and '..' directories. How would I get only the folders, and not those dots?
S = dir(path);
N = {S.name};
set(handles.listbox4,'String',N)

Akzeptierte Antwort

Adam
Adam am 16 Jun. 2017
S = dir( pathName );
N = { S( [ S.isdir ] ).name };
N = N( ~cellfun( @(x) strcmp( x, '.' ) || strcmp( x, '..' ), N ) );
set(handles.listbox4,'String',N)
should work fine. Your method would also pick up files as well as directories. I assume from your title that you don't want that.

Weitere Antworten (0)

Kategorien

Mehr zu File Operations 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