MATLAB - Get folder content as a string array


MATLAB - Get folder content as a string array



I need to get the content of the selected folder as an array of strings in order to run a script for each file in a for loop. The way I am currently doing it I receive the content as a char two dimensional array.



Is there a way to get the contents directly as a string array instead of running each row in a loop and converting it to a String?


directory = uigetdir;
list = ls(strcat(directory, '*.extension'))

for i = 1: ??




1 Answer
1



You want to use the dir function:


dir


list = dir(fullfile(directory, '*.extension'));
for ii=1:numel(list)
fullfile(list(ii).foler, list(ii).name)
end





You can skip the for-loop and just do fullfile({list.folder}, {list.name})
– matlabbit
Jun 29 at 22:49





@matlabbit: Thanks for that addition. I didn't mention it because OP wants to "run a script for each file in a for loop", but it's good to have this here.
– Cris Luengo
Jun 29 at 23:01






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Export result set on Dbeaver to CSV

Opening a url is failing in Swift