file organisation using copyfile returns unknown error

1 visualizzazione (ultimi 30 giorni)
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 Commenti
Walter Roberson
Walter Roberson il 14 Lug 2021
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 il 14 Lug 2021
In that case, it's a bum deal, indeed! :(

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Big Data Processing in Help Center e File Exchange

Tag

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by