搜索文件并在VB中检索它的路径

时间:2017-04-06 16:43:11

标签: vb.net

我试图搜索文件"prince.exe",并使用VB.Net检索它的文件路径,但我找不到这样做的方法。我想你可能能够使用命令提示符,但我不确定如何。

Private Sub Main_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    'Search for file and retrive path'
End Sub

1 个答案:

答案 0 :(得分:0)

Use the GetFiles function of System.IO.Directory. Make sure to use the overload that lets you pass the SearchOption value of AllDirectories.

Dim strStartingDirectory As String = "C:\YourStarting\Directory\"
Dim lstMatches As List(of string) = System.IO.Directory.GetFiles(strStartingDirectory, _
                                                                 "prince.exe", System.IO.SearchOption.AllDirectories).ToList()