ordering a listbox by extension
3 views (last 30 days)
Show older comments
Is it possible to load two types of files into a list box BUT order not by filename but with the same extensions.
I use this, but it appears to order by date. I would like to group the two sets of files together so If I am only loading *.jpg and *.xls, I need all the jpgs ordered first, and then all the xls.
for Index = 1:length(ImageFiles)
baseFileName = ImageFiles(Index).name;
[folder1, name, extension] = fileparts(baseFileName);
extension = upper(extension);
ListOfImageNames = [ListOfImageNames baseFileName];
end
set(handles.listbox1, 'string', ListOfImageNames);
0 Comments
Answers (1)
Joseph Cheng
on 8 Dec 2014
two ways to accomplish this, stack the extensions as well and use sort/sortrows to order the extensions. with the sorting functions you can get the reordering index and apply that to your list of files.
second method would be how you're creating your list of files. are you using dir()? if so you can use the wildcard filter in it to compile 2 lists.
ImageFiles=dir('yourFolder\*.jpg'); %to get the list of jpegs
XLSfiles=dir('yourfolder\*.xls'); %to get the list of xls files
set(handles.listbox1,'string',[ImageFiles;XLSfiles]);
See Also
Categories
Find more on Shifting and Sorting Matrices 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!