function dir_entries = dir_filter(dir_path, filters)    
dir_entries = dir(dir_path);
passed = ones(size(dir_entries));

% For each directory entry 
for i = 1:length(dir_entries)
    % For each of the different filters
    for j = 1:length(filters)
        filter = filters{j};
        
        % filter{1} is the filter type
        switch filter{1}
          case 'is_dir'
            passed(i) = dir_entries(i).isdir;
          case 'not_dir'
            passed(i) = ~dir_entries(i).isdir;                
          case 'name_is'
            passed(i) = any(strcmp(filter{2}, dir_entries(i).name));
          case 'name_not'
            passed(i) = ~any(strcmp(filter{2}, dir_entries(i).name));
          case 'name_regexp'
            passed(i) = ~isempty(regexp(dir_entries(i).name, filter{2}));
          case 'name_regexp_not'
            passed(i) = isempty(regexp(dir_entries(i).name, filter{2}));
          otherwise
            err = MException('DirFilter:BadFilter', ...
                             'Unrecognized filter type');
            throw(err)
        end
        
        % If this entry did not pass the filter we can stop now.
        if ~passed(i)
            break
        end
    end
end

dir_entries = dir_entries(logical(passed));

end
