function blocks = day_to_blocks_v2(datadir) all_folders = dir(datadir); all_folders = all_folders([all_folders(:).isdir]); all_folders = all_folders(~ismember({all_folders(:).name},{'.','..'})); blocks = length(all_folders); for b = 1:blocks clear block_number all_block_files block_number = str2num(all_folders(b).name(7:end)); block_pat = [all_folders(b).folder,'\',all_folders(b).name]; all_block_files = dir(fullfile(datadir,['*B',sprintf('%03.0f', block_number),'*'])); if length(all_block_files) ~= 14 % 2 instances by 3x2+2 files files_ok = input('The number of files is incorrect!! Do you really want to proceed? (1 = true): '); else files_ok = 1; end if files_ok for i = 1:length(all_block_files) movefile([datadir,'\',all_block_files(i).name],block_pat); end end end