populate load_listbox with a particular file extension

15 views (last 30 days)
it has been a long day, and this last hang up is driving me nuts. i give up. can someone please point out the obvious? i have tried so many things that just dont work. below is cut and paste from the unadulterated code. please show me what i havent been able to do for an hour. say i have 3 files: 101.csv, 101.csv.bak, and 101.mat. how do i list only the .csv. thanks in advance.
function load_listbox(dir_path, handles)
cd (dir_path)
dir_struct = dir(dir_path);
[sorted_names,sorted_index] = sortrows({dir_struct.name}');
handles.file_names = sorted_names;
handles.is_dir = [dir_struct.isdir];
handles.sorted_index = sorted_index;
guidata(handles.figure1,handles)
set(handles.listbox1,'String',handles.file_names,...
'Value',1)
set(handles.text1,'String',pwd)
end

Accepted Answer

Walter Roberson
Walter Roberson on 8 Sep 2011
Replace
dir_struct = dir(dir_path);
with
dir_struct = dir(fullfilename(dir_path, '*.csv'));
  1 Comment
ruprecht precht
ruprecht precht on 8 Sep 2011
Thanks for the quick response. It worked, but it was:
dir_struct = dir(fullfile(dir_path, '*.csv'));
my first time using dir!

Sign in to comment.

More Answers (0)

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!