diff --git a/Modules.Filesystem/File.vb b/Modules.Filesystem/File.vb
index 3caca1d5..30cd5203 100644
--- a/Modules.Filesystem/File.vb
+++ b/Modules.Filesystem/File.vb
@@ -120,7 +120,6 @@ Public Class File
Dim oExtension = Path.GetExtension(oFileName)
Dim oVersionSeparator As Char = "~"c
- Dim oFileVersion As Integer = Nothing
' Split Filename without extension at version separator to:
' - Check if file is already versioned
@@ -130,25 +129,31 @@ Public Class File
' test1.pdf --> test1 --> ['test1'] --> no fileversion
' test1~2.pdf --> test1~2 --> ['test1', '2'] --> version 2
' test1~12345~2.pdf --> test1~12345~2 --> ['test1', '12345', '2'] --> still version 2
- Dim oFileNameWithoutExtension = Path.GetFileNameWithoutExtension(oFileName)
- Dim oSplitFilename = oFileNameWithoutExtension.Split(oVersionSeparator).ToList()
+ 'Dim oFileNameWithoutExtension = Path.GetFileNameWithoutExtension(oFileName)
+ 'Dim oSplitFilename = oFileNameWithoutExtension.Split(oVersionSeparator).ToList()
' if file is already versioned, extract file version
' else just use the filename and set version to 1
- If oSplitFilename.Count > 1 Then
- Dim oVersion As Integer = 1
- Try
- oVersion = Integer.Parse(oSplitFilename.Last())
- oFileNameWithoutExtension = String.Join("", oSplitFilename.Take(oSplitFilename.Count - 1))
- Catch ex As Exception
- ' oFilenameWithoutExtension does NOT change
- oFileNameWithoutExtension = oFileNameWithoutExtension
- Finally
- oFileVersion = oVersion
- End Try
- Else
- oFileVersion = 1
- End If
+ 'If oSplitFilename.Count > 1 Then
+ ' Dim oVersion As Integer = 1
+ ' Try
+ ' oVersion = Integer.Parse(oSplitFilename.Last())
+ ' oFileNameWithoutExtension = String.Join("", oSplitFilename.Take(oSplitFilename.Count - 1))
+ ' Catch ex As Exception
+ ' ' oFilenameWithoutExtension does NOT change
+ ' oFileNameWithoutExtension = oFileNameWithoutExtension
+ ' Finally
+ ' oFileVersion = oVersion
+ ' End Try
+ 'Else
+ ' oFileVersion = 1
+ 'End If
+
+ Dim oFileNameWithoutExtension = Path.GetFileNameWithoutExtension(oFileName)
+ Dim oSplitResult = GetVersionedString(oFileNameWithoutExtension, oVersionSeparator)
+
+ oFileNameWithoutExtension = oSplitResult.Item1
+ Dim oFileVersion = oSplitResult.Item2
' Shorten the filename (only filename, without extension or version)
' by cutting the length in half. This should work no matter how long the path and/or filename are.
@@ -180,6 +185,45 @@ Public Class File
End Try
End Function
+ '''
+ ''' Split String at version separator to:
+ ''' check if string is already versioned,
+ ''' get the string version of an already versioned string
+ '''
+ '''
+ ''' Examples:
+ ''' test1.pdf --> test1 --> ['test1'] --> no fileversion
+ ''' test1~2.pdf --> test1~2 --> ['test1', '2'] --> version 2
+ ''' test1~12345~2.pdf --> test1~12345~2 --> ['test1', '12345', '2'] --> still version 2
+ ''' somestring~3 --> somestring~3 --> ['somestring', '3'] --> version 3
+ '''
+ ''' The string to versioned
+ ''' The character to split at
+ ''' Tuple of string and version
+ Public Function GetVersionedString(pString As String, pSeparator As Char) As Tuple(Of String, Integer)
+ Dim oSplitString = pString.Split(pSeparator).ToList()
+ Dim oStringVersion As Integer
+
+ ' if string is already versioned, extract string version
+ ' else just use the string and set version to 1
+ If oSplitString.Count > 1 Then
+ Dim oVersion As Integer = 1
+ Try
+ oVersion = Integer.Parse(oSplitString.Last())
+ pString = String.Join("", oSplitString.Take(oSplitString.Count - 1))
+ Catch ex As Exception
+ ' pString does NOT change
+ pString = pString
+ Finally
+ oStringVersion = oVersion
+ End Try
+ Else
+ oStringVersion = 1
+ End If
+
+ Return New Tuple(Of String, Integer)(pString, oStringVersion)
+ End Function
+
Public Function GetAppDataPath(CompanyName As String, ProductName As String)
Dim oLocalAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
Return Path.Combine(oLocalAppData, CompanyName, ProductName)
diff --git a/Modules.Filesystem/My Project/AssemblyInfo.vb b/Modules.Filesystem/My Project/AssemblyInfo.vb
index 2ae924dd..15366762 100644
--- a/Modules.Filesystem/My Project/AssemblyInfo.vb
+++ b/Modules.Filesystem/My Project/AssemblyInfo.vb
@@ -13,7 +13,7 @@ Imports System.Runtime.InteropServices
-
+
@@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
' übernehmen, indem Sie "*" eingeben:
'
-
-
+
+