简体   繁体   中英

VB Show File/Folder Names

I am coding a programm that will run some batch files if they're selected by the user.

Each batch has its own folder in a specific "resources" folder.

I am looping through that folder to create checkboxes and labels. Everything's working fine, but I don't want the label to have the whole path - I just want to display the foldername.

CODE :

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    Dim BatchFolder As IEnumerable = Directory.EnumerateFileSystemEntries(appPath & "/resources")
    Dim totalNumber As Integer = Directory.GetDirectories(appPath & "/resources").Length
    Dim i As Integer = 1

    For Each dir As String In BatchFolder
        Dim Label As New Label()
        Label.Name = "Lb_" & dir
        Label.Text = dir & ".bat"
        Label.AutoSize = True
        Label.Visible = True
        Label.Location = New Point(55, 4 + 25 * i)
        Dim CustomCheckbox As New Bunifu.Framework.UI.BunifuCheckbox()
        CustomCheckbox.Visible = True
        CustomCheckbox.Name = "CB_" & dir
        CustomCheckbox.Checked = False
        CustomCheckbox.Location = New Point(35, 25 * i)
        CustomCheckbox.CheckedOnColor = Color.FromArgb(12, 106, 255)
        Panel5.Controls.Add(Label)
        Panel5.Controls.Add(CustomCheckbox)
        i = i + 1
    Next
    Label21.Text = totalNumber
End Sub

This is how it looks:

在此处输入图片说明

You can do it like this :

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Dim BatchFolder As IEnumerable = Directory.EnumerateFileSystemEntries(appPath & "\resources")
    Dim totalNumber As Integer = Directory.GetDirectories(appPath & "\resources").Length
    Dim i As Integer = 1

    For Each dir As String In BatchFolder
        Dim Label As New Label()
        dir = dir.Substring(dir.LastIndexOf("\") + 1)
        Label.Name = "Lb_" & dir
        Label.Text = dir & ".bat"
        Label.AutoSize = True
        Label.Visible = True
        Label.Location = New Point(55, 4 + 25 * i)
        Dim CustomCheckbox As New Bunifu.Framework.UI.BunifuCheckbox()
        CustomCheckbox.Visible = True
        CustomCheckbox.Name = "CB_" & dir
        CustomCheckbox.Checked = False
        CustomCheckbox.Location = New Point(35, 25 * i)
        CustomCheckbox.CheckedOnColor = Color.FromArgb(12, 106, 255)
        Panel5.Controls.Add(Label)
        Panel5.Controls.Add(CustomCheckbox)
        i = i + 1
    Next
    Label21.Text = totalNumber
End Sub

Hope it will help you :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM