仅使用文件名vb.net的一部分来检索目录

时间:2016-06-03 15:09:00

标签: vb.net

我要检索记事本txt文件的目录,但我只有记事本的部分文件名?有可能这样做,任何快速的方式?我正在使用vb 2010 express来获取您的信息

1 个答案:

答案 0 :(得分:0)

''' <summary>
''' Gets all dirctories containing the file which its part is specified.
''' </summary>
''' <param name="PartOfTXT">The file specified. Do not contain the TXT extension.</param>
''' <returns>All dirctories containing the file which its part is specified.</returns>
''' <remarks>Comment if anything is wrong.</remarks>
Function GetTXTDirectory(PartOfTXT As String) As String()
    Dim List As New System.Collections.Generic.List(Of String)
    For Each Drive As System.IO.DriveInfo In System.IO.DriveInfo.GetDrives
        List.AddRange(System.IO.Directory.GetFiles(
            Drive.Name, "*"c & PartOfTXT & "*.txt", IO.SearchOption.AllDirectories))
    Next
    Return List.ToArray
End Function