Sort a list of files using Remainder after division
2 views (last 30 days)
Show older comments
Ines Rivoalen
on 13 Jun 2018
Commented: Ines Rivoalen
on 13 Jun 2018
Hello everyone, (i am french so I hope I will be clear) I have hundreds of files numerated like in attachment. I would like to put the files number 1,5,9,13… in a folder named "slice1", 2,6,10,14, in "slice2" … another 3,7,11,15… "slice3" and finally one with 4,8,12,16,.. in "slice4' i.e. i want to make folders separated with their reminder after division per 4 : all with reminder=1 in slice1, all with r=2 "slice2', r=3 'slice3' and r=0 'slice4' I searched in a lot of website and i really don't know how to c;puts it for separating all this files in different folders like this. I would be very happy if you could help me !! best regards
0 Comments
Accepted Answer
Stephen23
on 13 Jun 2018
Edited: Stephen23
on 13 Jun 2018
Here is an outline of one way to do it (untested, but should get you started):
D = 'original folder';
S = dir(fullfile(D,'*MRDC*.*'));
[~,C] = cellfun(@fileparts,{S.name},'uni',0);
N = str2double(regexp(C,'\d+$','once','match'));
for k = 1:numel(S)
F = sprintf('slice%d',mod(N(k)-1,4)+1);
movefile(fullfile(D,S(k).name),fullfile(F,S(k).name))
end
More Answers (0)
See Also
Categories
Find more on Shifting and Sorting Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!