【问题标题】:Get full path to .exe file if only a subfolder path to it is given如果仅给出了 .exe 文件的子文件夹路径,则获取该文件的完整路径
【发布时间】:2019-10-21 02:40:06
【问题描述】:

我必须找到存在于名为 bin 的文件夹中的 rscript.exe,但我没有对该文件夹的完整引用。

完整参考将是:

C:\Program Files\R\R-3.5.3\bin

但我事先不知道版本部分。所以我必须去

C:\Program Files\R 并在子文件夹中搜索 rscript.exe 并接收到它的完整路径。

我已经搜索过了,但我能找到的只是如何找出running application via reflections 的路径,并尝试在没有任何解决方案的情况下重写代码。有人可以帮我吗?

【问题讨论】:

    标签: vb.net path


    【解决方案1】:

    您可以使用带有searchPattern 参数的Directory.GetDirectories 方法并遍历子目录:

    Dim rootPath As String = "C:\Program Files\R"
    
    If Directory.Exists(rootPath) Then
        Dim currPath As String
    
        For Each subFolder As String In IO.Directory.GetDirectories(rootPath, "R-*", SearchOption.TopDirectoryOnly)
            currPath = IO.Path.Combine(subFolder, "bin", "rscript.exe")
    
            If IO.File.Exists(currPath) Then
                MessageBox.Show("File found at " & currPath)
            End If
        Next
    End If
    

    【讨论】:

      猜你喜欢
      • 2015-06-15
      • 1970-01-01
      • 2011-07-10
      • 1970-01-01
      • 1970-01-01
      • 2022-12-21
      • 2011-04-13
      • 2014-11-05
      • 1970-01-01
      相关资源
      最近更新 更多