How to create an array of files names from a structure created by 'dir' result?

100 ビュー (過去 30 日間)
Lilah Marziano
Lilah Marziano 2020 年 12 月 14 日
コメント済み: Jon 2020 年 12 月 14 日
Hi,
I have a folder with multiple txt files and I would like to create an array of the files names.
I used the 'dir' function and recieved a structures with field for every file.
Now I would like to create an array of all the files names, how do I do that?
Thank you.

回答 (1 件)

Jon
Jon 2020 年 12 月 14 日
編集済み: Jon 2020 年 12 月 14 日
This will put them into a cell array
list = dir('*.txt')
filenames = {list.name}
  1 件のコメント
Jon
Jon 2020 年 12 月 14 日
You can make a string array using
list = dir('*.txt')
filenames = string({list.name})
I'm not sure whether there is a way to go directly from list.name to a string array without the intermediate curly braces to make a cell array. Not a big issue, but maybe someone can suggest a cleaner way to to do this.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by