简体   繁体   English

VB显示文件/文件夹名称

[英]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 :) 希望它能对您有所帮助:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 vb.net 将文件复制到文件夹(每个文件夹 80 个文件) - vb.net copy file to folder (80 files per folder) vb.net从复制中排除特定文件名? - vb.net exclude specific file names from copying? 排序文件夹名称数组,如Windows资源管理器(数字和字母) - VB.NET - Sorting an array of folder names like Windows Explorer (Numerically and Alphabetically) - VB.NET 从文件/文件夹名称将剧集按动漫类别分类 - Sort episodes into Anime based categories from file/folder names 使用Powershell从网络文件夹中获取文件名 - Using Powershell to get just the file names from a network folder VIsual Studio 2010显示aspx文件的.vb和.designer.vb文件 - VIsual Studio 2010 Show .vb and .designer.vb file for an aspx file 如何在vb.net中创建变量,变量名称是从XML文件读取的元素名称 - How to create variables in vb.net with variable names being element name which are read from an xml file 如何使用C#/ Vb.Net在Windows Server 2003及更高版本上“删除-保护”文件或文件夹? - How to **delete-protect** a file or folder on Windows Server 2003 and onwards using C#/Vb.Net? 是否可以将“ AutoComplete.vb”文件移出App_Code文件夹并移至新的命名空间/项目中? - Is it possible to move the “AutoComplete.vb” file out of the App_Code folder and into a new namespace/project? 当其他应用程序正在创建新文件时,从文件夹中检索文件名 - Retrieve File Names from a folder while new files are being created by other application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM