diff --git a/+PlotID/createFileCopy.m b/+PlotID/createFileCopy.m index 10ac4e7100e4143edcf33de37f5d4dd9bddbd05f..f27ea2e9620b64af626843aadd6af923441f9d66 100644 --- a/+PlotID/createFileCopy.m +++ b/+PlotID/createFileCopy.m @@ -38,38 +38,40 @@ end RemotePath = fullfile(storPath,folderName, newfile); % Check if remote file already exists - count = 0; - while isfile(RemotePath) && ismember(type,{'data','dataCentral'}) - % Add a Sufix number to new file name - % TODO add more inteligent way then a simple sufix - count = count + 1; - [~,name,ext] = fileparts(RemotePath); - if count < 2 - RemotePath = fullfile(storPath,folderName,... - [name,'_',num2str(count),ext]); - else - RemotePath = fullfile(storPath,folderName,... - [name(1:end-length(num2str(count))),num2str(count),ext]); - end - [~, name, ~] = fileparts(RemotePath); - + + if isfile(RemotePath) && ismember(type,{'data','dataCentral'}) + % Add a Sufix number to new file name + [~,name,ext] = fileparts(RemotePath); - msg = ['Filename ',name,... - ' already exists in the data folder' newline,... - ' PlotID will add an suffix if you continue.' newline,... - ' This can cause serious confusions.']; + % User Dialog + msg = ['Filename ',name, ' already exists in the data folder' newline,... + ' PlotID will add an suffix if you continue.' newline,... + ' This can cause serious confusions.']; warning(msg); m = input('Do you want to continue, Y/N [Y]:','s'); if ismember(m,{'N','n'}) errorMSG = ['Filename already exists in data folder.' newline,... ' Rename the File and restart PlotID.']; - error(); - end - end + error(errorMSG); + end + % add sufix + RemotePath = fullfile(storPath,folderName,... + [name,'_1',ext]); + + % auto count until a sufix is reached that did not + % exist. (User is only asked once) + count = 0; + while isfile(RemotePath) + count = count + 1; + [~,name,~] = fileparts(RemotePath); + RemotePath = fullfile(storPath,folderName,... + [name(1:end-length(num2str(count-1))),num2str(count),ext]); + end + end%if copyfile(FileNameAndLocation,RemotePath); storagePaths{i} = RemotePath; - end + end %for status = true; msg =([type, ' successfully published']); % catch