From d5d196c8abb0673443d334b610b6bc89fd1a516e Mon Sep 17 00:00:00 2001 From: Jan Lemmer <jan.lemmer@fst.tu-darmstadt.de> Date: Tue, 10 Aug 2021 11:37:18 +0200 Subject: [PATCH] Closes #17 Fixes Error for single File copying --- fcn_core/Publish.m | 2 +- fcn_help/createFileCopy.m | 25 +++++++++++++++---------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/fcn_core/Publish.m b/fcn_core/Publish.m index 75473df..4fd760a 100644 --- a/fcn_core/Publish.m +++ b/fcn_core/Publish.m @@ -69,7 +69,7 @@ switch options.Method sourcePath = fList.name{idx}; createLinkedHDF5(sourcePath,storPath,ID); else % no identical file exists - createFileCopy(DataPaths.rdata,'data',storPath,ID,'dataCentral'); + createFileCopy(DataPaths.rdata{i},'data',storPath,ID,'dataCentral'); end end case 'individual' diff --git a/fcn_help/createFileCopy.m b/fcn_help/createFileCopy.m index 67b1620..19b278c 100644 --- a/fcn_help/createFileCopy.m +++ b/fcn_help/createFileCopy.m @@ -2,7 +2,12 @@ function [] = createFileCopy(filePaths,folderName,storPath,ID,type) % Creates a copy of the files (can used for multiple paths in a cell array) % folderName is the name of the exporting folder disp(['start to copy ', type]); - + + if ~iscell(filePaths) + %fixes Issue if Filepath is a char and not a cell array + filePaths = {filePaths}; + end + % try for i = 1:numel(filePaths) FileNameAndLocation = filePaths{i}; @@ -28,15 +33,15 @@ function [] = createFileCopy(filePaths,folderName,storPath,ID,type) % Write the file RemotePath = fullfile(storPath,folderName, newfile); - % Check if remote file already exists (not working) -% count = 0; -% while isfile(RemotePath) && ismember(type,{'data','dataCentral'}) -% % Add a Sufix number to file name -% count = count + 1; -% [~,name,ext] = fileparts(RemotePath); -% RemotePath = fullfile(storPath,folderName,... -% [name,'_',num2str(count),ext]); -% end +% Check if remote file already exists + count = 0; + while isfile(RemotePath) && ismember(type,{'data','dataCentral'}) + % Add a Sufix number to new file name + count = count + 1; + [~,name,ext] = fileparts(RemotePath); + RemotePath = fullfile(storPath,folderName,... + [name,'_',num2str(count),ext]); + end copyfile(FileNameAndLocation,RemotePath); end disp([type, ' sucessfully published']); -- GitLab