From 495672d46d5478bd31539a8b3c6df644b3c6aff5 Mon Sep 17 00:00:00 2001 From: Pierre Bellec Date: Fri, 5 Aug 2016 00:36:06 -0400 Subject: [PATCH] Added the ability to exclude files when grabbing a folder or comparing folder contents. --- extensions/niak_test/niak_brick_cmp_files.m | 18 ++++++++------ extensions/niak_test/niak_grab_folder.m | 27 +++++++++++++++------ 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/extensions/niak_test/niak_brick_cmp_files.m b/extensions/niak_test/niak_brick_cmp_files.m index 346c261f..af81aa2b 100644 --- a/extensions/niak_test/niak_brick_cmp_files.m +++ b/extensions/niak_test/niak_brick_cmp_files.m @@ -16,10 +16,12 @@ % OPT (structure) with the following fields: % BASE_SOURCE (string, mandatory) the base folder for SOURCE files. % BASE_TARGET (string, mandatory) the base folder for TARGET files. -% BLACK_LIST_SOURCE (string) the black list to grab files from SOURCE, -% if IN.SOURCE is omitted. -% BLACK_LIST_TARGET (string) the black list to grab files from TARGET, -% if IN.TARGET is omitted. +% BLACK_LIST_SOURCE (string or cell of strings) a list of folders to ignore +% in SOURCE, if IN.SOURCE is omitted. Please specify full paths. +% BLACK_LIST_TARGET (string or cell of strings) a list of folders to ignore +% in TARGET, if IN.SOURCE is omitted. Please specify full paths. +% EXCLUDE_FILES (string or cell of strings) a list of file names to exclude +% from the comparison. Names should not include folders, e.g. 'toto.txt'. % EPS (scalar, default 10^(-4)) the amount of "numeric noise" tolerated to % declare two volumes to be equal % FLAG_SOURCE_ONLY (boolean, default false) when comparing two matlab structures, @@ -128,8 +130,8 @@ end %% Options -list_fields = { 'flag_ignore_format' , 'base_source' , 'base_target' , 'black_list_source' , 'black_list_target' , 'flag_source_only' , 'eps' , 'flag_verbose' , 'flag_test' }; -list_defaults = { false , NaN , NaN , {} , {} , false , 10^(-4) , true , false }; +list_fields = { 'exclude_files' , 'flag_ignore_format' , 'base_source' , 'base_target' , 'exclude_files' , 'black_list_source' , 'black_list_target' , 'flag_source_only' , 'eps' , 'flag_verbose' , 'flag_test' }; +list_defaults = { {} , false , NaN , NaN , {} , {} , {} , false , 10^(-4) , true , false }; opt = psom_struct_defaults(opt,list_fields,list_defaults); if ~isempty(opt.base_source) @@ -146,11 +148,11 @@ in = psom_struct_defaults(in,{'source','target'},{{},{}}); if isempty(in.source) - in.source = niak_grab_folder(opt.base_source,opt.black_list_source); + in.source = niak_grab_folder(opt.base_source,opt.black_list_source,exclude_files); end if isempty(in.target) - in.target = niak_grab_folder(opt.base_target,opt.black_list_target); + in.target = niak_grab_folder(opt.base_target,opt.black_list_target,exclude_files); end if ~iscellstr(in.source)||~iscellstr(in.target) diff --git a/extensions/niak_test/niak_grab_folder.m b/extensions/niak_test/niak_grab_folder.m index ce9b777b..5db79e52 100644 --- a/extensions/niak_test/niak_grab_folder.m +++ b/extensions/niak_test/niak_grab_folder.m @@ -1,8 +1,8 @@ - function files = niak_grab_folder(path_data,black_list) + function files = niak_grab_folder(path_data,black_list,exclude_files) % Grab all the files inside a folder (recursively) % % SYNTAX: -% FILES = NIAK_GRAB_FOLDER(PATH_DATA,BLACK_LIST) +% FILES = NIAK_GRAB_FOLDER(PATH_DATA,BLACK_LIST,EXCLUDE_FILES) % % _________________________________________________________________________ % INPUTS: @@ -11,10 +11,13 @@ % (string, default [pwd filesep], aka './') a folder % % BLACK_LIST -% (string or cell of string) a list of folder (or subfolders) to -% be ignored by the grabber. Absolute names should be used -% (i.e. '/home/user23/database/toto' rather than 'toto'). If not, the names -% will be assumed to refer to the current directory. +% (string or cell of string) a list of folders to be ignored by the grabber. +% Absolute names should be used (i.e. '/home/user23/database/toto' rather +% than 'toto'). If not, the names will be assumed to refer to the current +% directory. +% +% EXCLUDE_FILES (string or cell of strings) a list of file names to exclude +% from the list. Names should not include folders, e.g. 'toto.txt'. % % _________________________________________________________________________ % OUTPUTS: @@ -68,6 +71,16 @@ elseif ischar(black_list) black_list = {niak_full_path(black_list)}; end +else + black_list = {}; +end + +%% List of excluded files +if (nargin < 3) + exclude_files = {}; +end +if ischar(exclude_files) + exclude_files = {exclude_files}; end %% List of folders @@ -79,7 +92,7 @@ files_loc = dir(path_data); is_dir = [files_loc.isdir]; files_loc = {files_loc.name}; -mask = ~ismember(files_loc,{'.','..'}); +mask = ~ismember(files_loc,{'.','..'})&~ismember(files_loc,exclude_files); is_dir = is_dir(mask); files_loc = files_loc(mask); files_loc = strcat(repmat({path_data},size(files_loc)),files_loc);