我可以检查一个目录是否只存在其名称的一部分吗?

时间:2014-11-29 13:24:21

标签: vb.net string

我想检查JDK是否已安装。

我不想检查C:\Program Files\Java\jdk1.8.0_25是否存在,因为用户可能安装了旧版本。 我想检查C:\Program Files\Java 中是否包含字符串jdk

我能这样做吗?

4 个答案:

答案 0 :(得分:0)

步骤1:获取所有目录名称的列表。 Link

步骤2:检查一个或多个是否包含searchstring。 Link

答案 1 :(得分:0)

Dim Installed = (
    From i In My.Computer.FileSystem.GetDirectories("C:\Program Files\Java")
    Where i.ToLower Like "*jdk*").Any

答案 2 :(得分:0)

简单的注册表检查。您需要添加错误捕获等。

Dim rk As RegistryKey
Dim sk As RegistryKey
Dim currentVerion As String


rk = Registry.LocalMachine

sk = rk.OpenSubKey("SOFTWARE\\JavaSoft\\Java Runtime Environment")
If sk Is Nothing Then
    'Does not exist (IE Could not open it).
Else
    currentVerion = sk.GetValue("CurrentVersion").ToString()
End If

答案 3 :(得分:-1)

直接来自MSDN

Try
    Dim dirPath As String = "your directory where JDK might be present" 
    Dim dirs As List(Of String) = New List(Of String)(Directory.EnumerateDirectories(dirPath))
    For Each folder In dirs
        ' Logic to check existence of word "JDK" from end
        ' If found break
    Next
Catch UAEx As UnauthorizedAccessException
    ' Error Handling
Catch PathEx As PathTooLongException
    ' Error Handling
End Try