From df421227f50194e8b4d0da94c9e383d3179bc321 Mon Sep 17 00:00:00 2001
From: "M. Hock" <martin.hock@fst.tu-darmstadt.de>
Date: Fri, 24 Sep 2021 16:35:41 +0200
Subject: [PATCH] Fix for adding Suffix each time instead of only once.

Changed  tesdata_2 to testdata2 to avoid confusion with suffix.
---
 +PlotID/createFileCopy.m | 9 +++++++--
 .gitignore               | 2 ++
 PlotID_Demo.m            | 6 +++---
 example.m                | 4 ++--
 4 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/+PlotID/createFileCopy.m b/+PlotID/createFileCopy.m
index c77e355..3f415ef 100644
--- a/+PlotID/createFileCopy.m
+++ b/+PlotID/createFileCopy.m
@@ -42,8 +42,13 @@ function [] = createFileCopy(filePaths,folderName,storPath,ID,type)
                 % TODO add more inteligent way then a simple sufix
                 count = count + 1;
                 [~,name,ext] = fileparts(RemotePath);
-                RemotePath = fullfile(storPath,folderName,...
-                    [name,'_',num2str(count),ext]);
+                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    
                 warning('Filename already exists in data folder');
             end
             copyfile(FileNameAndLocation,RemotePath);
diff --git a/.gitignore b/.gitignore
index abeaca8..ddff563 100644
--- a/.gitignore
+++ b/.gitignore
@@ -31,8 +31,10 @@ codegen/
 test*.m
 test123_data.h5
 
+
 # files that are created in example.m
 testdata_2.h5
+testdata2.h5
 test_data.mat
 export/*
 
diff --git a/PlotID_Demo.m b/PlotID_Demo.m
index ac720c0..2914c4f 100644
--- a/PlotID_Demo.m
+++ b/PlotID_Demo.m
@@ -5,7 +5,7 @@
 clear; clc; close all;
 addpath('CI_files'); % Test scripts
 try
-    delete testdata_2.h5;
+    delete testdata2.h5;
 end
 
 %% Set ProjectID
@@ -28,8 +28,8 @@ y1 = sin(x1)+.5*sin(2*x1)+2;
 
 % define file path & name
 
-fpath = fullefile(pwd,"./testdata_2.h5");
-dataset2 = fullfile(pwd,'testdata_2.h5');
+fpath = fullefile(pwd,"./testdata2.h5");
+dataset2 = fullfile(pwd,'testdata2.h5');
 
 % create hdf5 file and dataset > write data to hdf5 file / dataset
 h5create(fpath, "/x1", size(x1), "Datatype", class(x1))
diff --git a/example.m b/example.m
index c73c83a..dfb5647 100644
--- a/example.m
+++ b/example.m
@@ -6,7 +6,7 @@ clear; clc; close all;
 addpath('CI_files'); % Test scripts
 
 try
-    delete testdata_2.h5;
+    delete testdata2.h5;
 end
 
 
@@ -37,7 +37,7 @@ x1 = linspace(0,2*pi);
 y1 = sin(x1)+2;
 
 % define file path & name
-dataset2 = 'testdata_2.h5';
+dataset2 = 'testdata2.h5';
 dataset2 = fullfile(pwd,dataset2);
 fpath = dataset2;
 
-- 
GitLab