I got a struct after using dir(directoryName)
. I want to get a vector containing all the file names in that folder.
- How do I extract a vector of names from the struct?
- Is there a better way to get a vector with the names of all files in a directory?
Here's how you can do this:
This works by making use of comma-separated lists. When you have a structure array and you index a field with the dot operator, you get a comma-separated list of values that you can then pass to a function or collect with square or curly brackets. This code:
Collects the
isdir
field from every structure in the array, putting the values in a vector using square brackets so it can be used as a logical index. Then this code:Collects the
name
field from every structure in the array, putting the strings in a cell array.