2 Commits

Author SHA1 Message Date
Jonathan Jenne
dfb53d60e6 Filesystem: Version 1.0.1.0 2020-04-30 11:40:54 +02:00
Jonathan Jenne
3ad3519201 Filesystem: Add GetCleanFilename and GetCleanPath 2020-04-30 11:40:18 +02:00
2 changed files with 35 additions and 1 deletions

View File

@@ -1,4 +1,5 @@
Imports System.IO
Imports System.Text.RegularExpressions
Imports DigitalData.Modules.Logging
''' <module>File</module>
@@ -24,13 +25,46 @@ Public Class File
Private ReadOnly _logger As Logger
Private ReadOnly _logConfig As LogConfig
Private ReadOnly _invalidFilenameChars As String
Private ReadOnly _invalidPathChars As String
Private Const REGEX_CLEAN_FILENAME As String = "[\\/:""<>|\b\0\r\n\t]"
Private Const REGEX_CLEAN_PATH As String = "[:""<>|\b\0\r\n\t]"
Private Const FILE_NAME_ACCESS_TEST = "accessTest.txt"
Public Sub New(LogConfig As LogConfig)
_logConfig = LogConfig
_logger = LogConfig.GetLogger()
_invalidFilenameChars = String.Join("", Path.GetInvalidFileNameChars())
_invalidPathChars = String.Join("", Path.GetInvalidPathChars())
End Sub
Public Function GetCleanFilename(FileName As String) As String
_logger.Debug("Filename before cleaning: [{0}]", FileName)
Dim oCleanName As String = FileName
oCleanName = Regex.Replace(oCleanName, _invalidFilenameChars, String.Empty)
oCleanName = Regex.Replace(oCleanName, REGEX_CLEAN_FILENAME, String.Empty, RegexOptions.Singleline)
_logger.Debug("Filename after cleaning: [{0}]", oCleanName)
Return oCleanName
End Function
Public Function GetCleanPath(FilePath As String) As String
_logger.Debug("Path before cleaning: [{0}]", FilePath)
Dim oCleanName As String = FilePath
oCleanName = Regex.Replace(oCleanName, _invalidPathChars, String.Empty)
oCleanName = Regex.Replace(oCleanName, REGEX_CLEAN_FILENAME, String.Empty, RegexOptions.Singleline)
_logger.Debug("Path after cleaning: [{0}]", oCleanName)
Return oCleanName
End Function
''' <summary>
''' Adds fileversions to given filename `Destination` if that file already exists.
''' </summary>

View File

@@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
' übernehmen, indem Sie "*" eingeben:
' <Assembly: AssemblyVersion("1.0.*")>
<Assembly: AssemblyVersion("0.0.0.1")>
<Assembly: AssemblyVersion("1.0.1.0")>
<Assembly: AssemblyFileVersion("1.0.0.0")>