function selected_info = select_file_info(file_info, select)

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

if isstruct(select)
    selected_info.file = file_info.file(select.file);
    
    if isfield(select, 'subdir_select')
        selected_inds = find(select.subdir);
        for i = 1:length(selected_inds)
            selected_info.subdir(i) = ...
                select_file_info(file_info.subdir(selected_inds(i)), ...
                                 select.subdir_select(selected_inds(i)));
        end
    else
        selected_info.subdir = file_info.subdir(select.subdir);
    end
        
elseif length(file_info.subdir) == length(select)
    selected_info.subdir = file_info.subdir(select);
elseif length(file_info.file) == length(select)
    selected_info.file = file_info.file(select);
else
    error(['second argument length does not match directory structure']);
end    

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



