MATLAB Answers

file organisation using copyfile returns unknown error

2 ビュー (過去 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};
bmp_path = '/Users/sm/Downloads/summer project/input';
I = dir(fullfile(bmp_path,'*.bmp'))
Ilist = {};
%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
for kk = 1 : length(Ilist)
matchedIdx = find( cellfun(@(x) contains(name,x),dcm));
copyfile(fullfile(mainfolder, dcm{jj}), fullfile(parentfolder, '\', Plist{matchedIdx}))
result :
Unknown error occurred.
Error in sort_group (line 33)
copyfile(fullfile(mainfolder, dcm{jj}), fullfile(parentfolder, '\', Plist{matchedIdx}))
  5 件のコメント
dpb 2021 年 7 月 14 日
In that case, it's a bum deal, indeed! :(


回答 (0 件)





Community Treasure Hunt

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

Start Hunting!

Translated by