|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
VB.NET code to find path of file in system PATH?
Hello,
I am looking for a way to get the full path of a file that is in the system path environment variable using VB.NET. For example like in the FOR command in DOS: %~$PATH:I - searches the directories listed in the PATH environment variable and expands %I to the fully qualified name of the first one found. If the environment variable name is not defined or the file is not found by the search, then this modifier expands to the empty string Would it use System.IO.Path somehow? Thanks |
|
#2
|
|||
|
|||
|
I've been looking for an existing function in the framework that would do this but could not find one. So here's what I have instead:
Code:
Private paths() As String = Split(Environment.GetEnvironmentVariable("PATH"), ";")
Private messageOutput As String
Private fileInPath as String = "notepad.exe" ' for example
For Each pathItem In paths
If File.Exists(pathItem & "\" & fileInPath) Then
messageOutput += pathItem & vbCrLf
End If
Next
Msg(messageOutput)
Not too bad but is there a better way? |
![]() |
| Viewing: Dev Articles Community Forums > Programming > .NET Development > VB.NET code to find path of file in system PATH? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|