Public Class frmScriptFolder

    Private Sub frmScriptFolder_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Me.txtScriptFolder.Text = My.Settings.ExportDirectory
        lblResults.Text = ""
    End Sub

    Private Sub btnSave_Click(sender As System.Object, e As System.EventArgs) Handles btnSave.Click
        Dim p As String
        p = txtScriptFolder.Text
        If p.Substring(p.Length - 1, 1) <> "\" Or p.Substring(p.Length - 1, 1) <> "/" Then p = p & "\"

        My.Settings.ExportDirectory = p
        My.Settings.Save()
        Me.Close()
    End Sub

    Private Sub btnCancel_Click(sender As System.Object, e As System.EventArgs) Handles btnCancel.Click
        Me.Close()
    End Sub

    Private Sub btnCheckFolder_Click(sender As System.Object, e As System.EventArgs) Handles btnCheckFolder.Click
        lblResults.Text = ""
        Dim DI As IO.DirectoryInfo, FIs() As IO.FileInfo
        Dim p As String
        '' Verify Read of Script Folder
        p = txtScriptFolder.Text
        If p.Substring(p.Length - 1, 1) <> "\" Or p.Substring(p.Length - 1, 1) <> "/" Then p = p & "\"
        Try
            DI = New IO.DirectoryInfo(p)
            FIs = DI.GetFiles
            lblResults.Text = "Access Successful. " & p & " contains " & FIs.Count.ToString & " items."
        Catch ex As Exception
            Beep()
            lblResults.Text = "Access to " & p & " Failed:  " & ex.Message
        End Try
    End Sub

    Private Sub btnBrowse_Click(sender As Object, e As EventArgs) Handles btnBrowse.Click
        ''
        '' Open Dialog to select location of the HS script folder
        ''
        If fbdScriptFolder.ShowDialog() = DialogResult.OK Then
            txtScriptFolder.Text = fbdScriptFolder.SelectedPath
        End If
    End Sub

End Class