file organisation using copyfile returns unknown error
조회 수: 1 (최근 30일)
이전 댓글 표시
I'm trying to organise some files but somehow my code makes a folder with the name '\' and moves all the files i meant to move there. it just said unknown error with copy file this time. for context, the file i'm interested is located in /users/.../Daniel/P1 until P20 so i had to use a loop to extract all the dicom files under it. the folder i want to move the dicom files into is the nufolder. in the loop i made a folder for every dicom file name under nufolder, that's where i want to move the files into ( pic included for context )
%change file path here :
mainfolder ='/Users/sm/Downloads/summer project/CL2 Dicom/Daniel';%dicom images
parentfolder = '/Users/sm/Downloads/summer project/';
mkdir nufolder;
parentfolder = '/Users/sm/Downloads/summer project/nufolder';
P_f = dir( fullfile( mainfolder, '*'));
%Plist = setdiff({ P_f([P_f.isdir]).name},{'.','..'}); % works fine up to here
Plist = {P_f([P_f.isdir]).name};
Plist(1:2)=[];
bmp_path = '/Users/sm/Downloads/summer project/input';
I = dir(fullfile(bmp_path,'*.bmp'))
Ilist = {I.name};
%I = dir( fullfile( input, '*'))
%%
for ii = 1: numel(Plist)
P = dir( fullfile( mainfolder,Plist{ii}, '*.dcm'));
dcm = {P(~[P.isdir]).name}; % works great!! gets all the dicom file in the p files
for jj = 1 : numel(dcm)
[filepath, name, ext]= fileparts(dcm(jj)); % converts cell to string
mkdir( parentfolder, name); % makes folders after the dcm names in nufolder
end
for kk = 1 : length(Ilist)
matchedIdx = find( cellfun(@(x) contains(name,x),dcm));
copyfile(fullfile(mainfolder, dcm{jj}), fullfile(parentfolder, '\', Plist{matchedIdx}))
end
result :
Unknown error occurred.
Error in sort_group (line 33)
copyfile(fullfile(mainfolder, dcm{jj}), fullfile(parentfolder, '\', Plist{matchedIdx}))
댓글 수: 5
Walter Roberson
2021년 7월 14일
fullfile('abc', '\', 'def')
fullfile('abc', '/', 'def')
so on unix systems, the \ is kept as a literal character.
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Big Data Processing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!