matlab order of picking files from folder
2 views (last 30 days)
Show older comments
i am picking files from folder having more than 15K files and files are named as 1,2,3.....in sequential order. When I execute below code, I find files are selected at random and no sequential order is maintained. Any way to do it.
folder_content = dir ([my_folder,'*',file_ext]); num_files = size (folder_content,1);
for i=1:num_files string = [my_folder,folder_content(i,1).name]; [fpath fname fext]=fileparts(string); disp(fname); end
1 Comment
Titus Edelhofer
on 1 Jul 2011
Hi,
I'm not exactly sure what the problem is? You could use sort on {folder_content.name}. The dir does not allow for specifying how the files are sorted ...
Titus
Answers (1)
Jan
on 1 Jul 2011
Although this is not guaranteed, the reply of DIR is usually sorted alphabetically - at least I have not ssen any counter-example yet. Which OS are you using to get an randomly sorted result?
But the alphabetical sorting might differ from your expectations:
sort({'1', '2', '3', '10', '11', '20'})
>> '1' '10' '11' '2' '20' '3'
Do you want something else? Then use SSCANF to convert the strings to a number, and the 2nd output of SORT to get the sorting index in "natural" order.
0 Comments
See Also
Categories
Find more on File Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!