Matlab Script-Moving of multiple files from multiple folders into specific folders
조회 수: 2 (최근 30일)
이전 댓글 표시
Hallo, i need to write a script, wich moves multiple files from multiple folders into specific folders. There are 18 folders (shown in 1.jpg). Each of them contains two subfolders, as shown in 2.jpg. There are 80 files in Body 0.5 CE and 37 files in Body 1.5 CE (shown in 3.jpg and 4.jpg). The script should move 80 files (Body 0.5 CE) from each folder (140224.300, 140225.700, ...,140227.700) to complementary folder of t01, t02, ...t18 structure.
For example >> C:\Users\dan\Desktop\dicom1\sort\140224.300\Body 0.5 CE_Series0006...move to...C:\Users\dan\Desktop\PilotStudiexx_new_template\2-DynCT\0.5mm\t01. And so on, until content of all 18 folders is moved to t01-t18. After that i will use the same method for moving the Body 1.5 CE files. The script should be portable.
I hope i've expressed myself clearly. Any suggestion would be very helpfull!
Thank you!





댓글 수: 0
답변 (1개)
Guillaume
2016년 10월 3일
편집: Guillaume
2016년 10월 5일
If the destination folders don't already exist, then you could just rename the original folders. Assuming, the destination already exist, here is a rough, untested (there may be bugs/typos), outline of how I would do it:
srcroot = 'C:\Users\dan\Desktop\dicom1\sort\';
destroot = 'C:\Users\dan\Desktop\PilotStudiexx_new_template\2-DynCT\0.5mm';
rootdir = dir(srcroot); %get a list of all files and folders
srcfolders = {rootdir.name}; %put the names into cell array
srcfolders = srcfolders([rootdir.isdir] & ~ismember(srcfolders, {'.', '..'})); %only keep directories but not the '.' and '..' that matlab stupidly return.
for fldidx = 1:numel(srcfolders)
destfolder = fullfile(destroot, sprintf('t%02d', fldidx));
movefile(fullfile(srcroot, srcfolders{fldidx}, '*'), destfolder);
end
댓글 수: 7
Guillaume
2016년 10월 22일
Well, the intent of my latest code was to create the exact same structure that you describe, so if it doesn't it's because I've overlooked something. Rereading the code I can't see what it would be. The only missing thing is the 'mm' suffix to your directories, which is easily fixed, replace the sprintf('%g', scandistance) by:
sprintf('%gmm', scantdistance)
If the destination folders already exist, it should just fill them up with the moved content.
참고 항목
카테고리
Help Center 및 File Exchange에서 Performance and Memory에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!