MATLAB Answers

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

조회 수: 89(최근 30일)
Lilah Marziano
Lilah Marziano 2020년 12월 14일
댓글: Jon 2020년 12월 14일
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.


Jon 2020년 12월 14일
편집: Jon 2020년 12월 14일
This will put them into a cell array
list = dir('*.txt')
filenames = {}
  댓글 수: 1
Jon 2020년 12월 14일
You can make a string array using
list = dir('*.txt')
filenames = string({})
I'm not sure whether there is a way to go directly from 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.

댓글을 달려면 로그인하십시오.


Community Treasure Hunt

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

Start Hunting!

Translated by