Imports System.IO

Public Class clsHelper
    Public Shared Function Check_Folder(path As String)
        Try
            If Not IO.Directory.Exists(path) Then
                ' Nein! Jetzt erstellen...
                IO.Directory.CreateDirectory(path)
                ClassLogger.Add("Folder: '" & path & "' wurde erfolgreich angelegt", False)
                ' Ordner wurde korrekt erstellt!
            End If
            Return True
        Catch ex As Exception
            ClassLogger.Add("In clsHelper.Check_Folder - " & ex.Message, True)
            Return False
        End Try

    End Function
    Public Shared Function Prevent_Null(value)
        Select Case value.GetType.ToString
            Case "System.DBNull"
                Return Nothing
            Case Else
                Return value
        End Select
    End Function
    Public Shared Function func_check_file_use(ByVal sub_filename) As Boolean
        Dim fs As Integer = FreeFile()
        Dim inuse As Boolean = False
        If File.Exists(sub_filename) Then
            Try
                FileOpen(fs, sub_filename, OpenMode.Binary, _
                OpenAccess.ReadWrite, OpenShare.LockReadWrite)
            Catch
                inuse = True
            Finally
                FileClose(fs)
            End Try
        End If
        Return inuse
    End Function
    Public Shared Function file_exists(ByVal _file As String)
        Try
            If System.IO.File.Exists(_file) Then
                Return True
            Else
                Return False
            End If
        Catch ex As Exception
            ClassLogger.Add("In clsHelper.file_exists - " & ex.Message, True)
            Return False
        End Try
    End Function
    Public Shared Function Datei_Versionieren(Dateiname As String, LOG_ERR_ONLY As Boolean, modul As String)
        Try
            Dim version As Integer = 1
            Dim extension As String = Path.GetExtension(Dateiname) 'Quelldatei.Substring(Quelldatei.LastIndexOf("."))
            Dim Stammname As String = Path.GetDirectoryName(Dateiname)
            Dim neuername As String = Path.GetFileNameWithoutExtension(Dateiname)
            Dim endgueltigerDateiname As String = neuername & extension
            'Automatische Versionierung mit Tilde + Version
            Do While file_exists(Stammname & "\" & neuername & extension) = True
                ClassLogger.Add(" - Datei " & endgueltigerDateiname & " ist vorhanden - Datei wird versioniert", False)
                neuername = Stammname & "~" & version
                endgueltigerDateiname = neuername & extension
                version = version + 1
            Loop
            Return Stammname & "\" & neuername & extension
        Catch ex As Exception
            ClassLogger.Add("In clsHelper.Datei_Versionieren - " & ex.Message, True)
            Return Nothing
        End Try

    End Function
    Public Shared Function string_Contains(s As String, search As String)
        Return s.ToLower.Contains(search.ToLower)
    End Function
End Class
