file organisation using copyfile returns unknown error

조회 수: 1 (최근 30일)
sesilia maidelin
sesilia maidelin 2021년 7월 14일
댓글: dpb 2021년 7월 14일
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
Walter Roberson 2021년 7월 14일
fullfile('abc', '\', 'def')
ans = 'abc/\/def'
fullfile('abc', '/', 'def')
ans = 'abc/def'
so on unix systems, the \ is kept as a literal character.
dpb
dpb 2021년 7월 14일
In that case, it's a bum deal, indeed! :(

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Big Data Processing에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by