简体   繁体   English

Combobox只是文件名(没有扩展或路径)VB.Net

[英]Combobox just file name (without extention or path) VB.Net

I got the following code which is nice and all however it returns the entire path as well as name 我得到了以下代码,这很好,但它返回整个路径以及名称

        For Each s As String In System.IO.Directory.GetFiles("C:\VTS\TREADSTONE LT\ATC\BASIS\")
        combobox1.Items.Add(s)
    Next

What I'm after is the file name only and preferably without its extention... 我所追求的只是文件名,最好没有它的延伸......

UPDATE UPDATE

            For Each s As String In GetFileNameWithoutExtension("C:\VTS\TREADSTONE LT\ATC\BASIS\")
        combobox1.Items.Add(s)
    Next

You'll need to use the Path class inside the loop: 你需要使用循环Path类:

Dim dir = "C:\VTS\TREADSTONE LT\ATC\BASIS\"
For Each file As String In System.IO.Directory.GetFiles(dir)
    combobox1.Items.Add(System.IO.Path.GetFileNameWithoutExtension(file))
Next

Change your code to: 将您的代码更改为:

For Each s As String In System.IO.Directory.GetFiles("C:\VTS\TREADSTONE LT\ATC\BASIS\")
    s = s.Substring(0,s.LastIndexOf("."))
    combobox1.Items.Add(s)
Next
Dim di As New IO.DirectoryInfo(My.Application.Info.DirectoryPath + "\softbelldata")
Dim diar1 As IO.FileInfo() = di.GetFiles()
Dim dra As IO.FileInfo

'list the names of all files in the specified directory
For Each dra In diar1
    If dra.Extension = ".mdb" Then
        txtyear.Items.Add(System.IO.Path.GetFileNameWithoutExtension(dra.Name))
    End If
Next

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

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