file organisation using copyfile returns unknown error

3 次查看(过去 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
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.

请先登录,再进行评论。

回答(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