0

I have to find the rscript.exe that exists in a folder called bin but I do not have the full reference to this folder.

Full Reference would be:

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

but I do not know the version part beforehand. So I must go to

C:\Program Files\R and search the subfolders for the rscript.exe and recieve the full path to it.

I have already searched but all I could find was how to find out the path of the running application via reflections and tried out to rewrite the code without any solution. Could anyone help me here?

ruedi
  • 5,365
  • 15
  • 52
  • 88

1 Answers1

1

You can use the Directory.GetDirectories method with the searchPattern argument and loop throught the subdirectories:

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
MatSnow
  • 7,357
  • 3
  • 19
  • 31