1

我得到了以下代码,这很好,但是它返回了整个路径以及名称

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

我所追求的只是文件名,最好没有扩展名......

更新

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

3 回答 3

3

您需要在循环中使用 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
于 2013-05-24T07:57:27.587 回答
1

将您的代码更改为:

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
于 2013-05-24T07:26:00.543 回答
0
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
于 2014-02-03T07:17:03.250 回答