MATLAB Answers

Populate listbox with only directories?

1 ビュー (過去 30 日間)
Ibro Tutic
Ibro Tutic 2017 年 6 月 16 日
回答済み: Adam 2017 年 6 月 16 日
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 = {};

  0 件のコメント



Adam 2017 年 6 月 16 日
S = dir( pathName );
N = { S( [ S.isdir ] ).name };
N = N( ~cellfun( @(x) strcmp( x, '.' ) || strcmp( x, '..' ), 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.

  0 件のコメント


その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by