sorting files into 2 separate folders

4 次查看(过去 30 天)
Hi I am trying to sort some DICOM files (1584), by separating them and saving them into 2 separate folders. the way i need to separate them is every alternating 8 files goes to one of the 2 folders. so i think i need start counting 1-8 and put in 1 folder and the next 8 go to the other folder. I'm not sure how to proceed this is what i have till now
% sorting alternating data
path = 'C:\Users\......';
output_dir = uigetdir('','C:\Users\Sorted_GE_SE_Images');
dirs = dir('C:\Users\GE_SE_Images\....\10_ep2d_ge_se_128_DCE\*.dcm')
N = length(dirs);
for i = 1 : N;
for j = 1:8;
file_SE = dirs(j).name
copyfile(file_SE,'C:\Users\\Sorted_GE_SE_Images\SE_images')
for k = 9:16;
file_GE = dirs(k).name
copyfile(file_GE,'C:\Users\Sorted_GE_SE_Images\SE_images')
end
end
end

采纳的回答

per isakson
per isakson 2015-2-14
Maybe this will help you
sorting alternating data
path = 'C:\Users\......';
output_dir = uigetdir('','C:\Users\Sorted_GE_SE_Images');
dirs = dir('C:\Users\GE_SE_Images\....\10_ep2d_ge_se_128_DCE\*.dcm');
N = length(dirs);
for ii = 1 : 16 : N
sad = dirs(ii:min([N,ii+16]));
for jj = 1:length(sad)
file_SE = dirs(jj).name;
if jj<=8
copyfile( file_SE, 'C:\Users\Sorted_GE_SE_Images\SE_images')
else
copyfile( file_SE, 'C:\Users\Sorted_GE_SE_Images\GE_images')
end
end
end
  2 个评论
Hoda
Hoda 2015-2-14
编辑:per isakson 2015-2-14
Thanks alot Per, if you dont mind could you explain what this command
sad = dirs(ii:min([N,ii+16]));
does. Also tried to run your code but I get an error : Error using copyfile No matching files were found.
per isakson
per isakson 2015-2-14
The outer loop takes steps of 16 items of the file list except for the last where it takes the rest.
for ii = 1 : 16 : N
sad = dirs(ii:min([N,ii+16]));
sixteen items of the file list are copied to sad. The inner loop loops over the length of sad. Copying to sad makes the indexing simpler.
&nbsp
"Error using copyfile No matching files were found" &nbsp Replace
file_SE
by
fullfile( 'folder_name', file_SE )

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 File Operations 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by