-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind_and_count.m
70 lines (64 loc) · 2.77 KB
/
find_and_count.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
function result = find_and_count(root_folder_path, is_file_a_keeper_predicate, folder_filter_function)
seed = 0 ; % for counting, start with a count of zero
function result = filter(root_folder_path, base_folder_relative_path, file_name, depth, is_this_file_a_folder) %#ok<INUSD>
result = feval(is_file_a_keeper_predicate, root_folder_path, base_folder_relative_path, file_name) ;
end
result = file_accumulate_map_filter(root_folder_path, seed, @accumulator, @mapper, @filter, folder_filter_function) ;
end
function result = accumulator(result_so_far, file_value)
% For counting, just add the file_value to the ongoing count
result = result_so_far + file_value ;
end
function result = mapper(root_folder_path, base_folder_relative_path, file_name, depth) %#ok<INUSD>
% For counting, just want to return one for each file that gets past the
% filter
result = 1 ;
end
% function result = find_and_count(base_folder_path, is_file_a_keeper_predicate, varargin)
% [folder_predicate_function] = ...
% parse_keyword_args(...
% varargin, ...
% 'folder_predicate_function', @(folder_path, depth)(true)) ;
%
% result = ...
% find_and_count_helper(base_folder_path, ...
% is_file_a_keeper_predicate, ...
% folder_predicate_function, ...
% 0, ...
% 0) ;
% end
%
%
%
% function result = ...
% find_and_count_helper(base_folder_path, ...
% is_file_a_keeper_predicate, ...
% folder_predicate_function, ...
% depth, ...
% incoming_count)
% count_so_far = incoming_count ;
% [file_names, is_file_a_folder] = simple_dir(base_folder_path) ;
% file_count = length(file_names) ;
% for i = 1 : file_count ,
% file_name = file_names{i} ;
% is_this_file_a_folder = is_file_a_folder(i) ;
% file_path = fullfile(base_folder_path, file_name) ;
% if is_this_file_a_folder ,
% % if a folder satisfying predicate function, recurse
% if feval(folder_predicate_function, file_path, depth) ,
% count_so_far = ...
% find_and_count_helper(...
% file_path, ...
% is_file_a_keeper_predicate, ...
% folder_predicate_function, ...
% depth+1, ...
% count_so_far) ;
% end
% else
% if feval(is_file_a_keeper_predicate, file_path) ,
% count_so_far = count_so_far + 1 ;
% end
% end
% end
% result = count_so_far ;
% end