function selected_info = filter_file_info(file_info, select_function)

selected_info.name = file_info.name;
selected_info.num_files = 0;
selected_info.file = [];
selected_info.subdir = file_info.subdir;

for subdir_ind = 1:length(file_info.subdir)
    selected_info.subdir(subdir_ind) = ...
        filter_file_info(file_info.subdir(subdir_ind), select_function);
end

if ~isempty(file_info.file)
    select = cellfun(select_function, [file_info.file.tokens]);
    selected_info.file = file_info.file(select);
    selected_info.num_files = length(selected_info.file);
end

if ~isempty(selected_info.subdir)
    selected_info.num_files = sum([selected_info.subdir.num_files]) + ...
        selected_info.num_files;
end



