我試圖從一個VB.NET應用程序內運行目標相對路徑。我已經確保使用反斜槓(而不是正斜槓),並且還要將工作目錄設置爲正確的源路徑來運行Process;嘗試運行時仍出現The system cannot find the file specified
錯誤。在Windows中運行相對路徑?
例如,我有(僞代碼):
txtSource.text path = "C:\Windows\System32"
txtResult.text path = "..\notepad.exe"
這裏的小組到目前爲止:
Private Sub btnTest_Click(sender As Object, e As EventArgs) Handles btnTest.Click
Try
' Create the process object
Dim pRun As New Process()
' Set it to run from the Source folder (Working Directory)
With pRun.StartInfo
.UseShellExecute = False
.WorkingDirectory = IO.Path.GetDirectoryName(txtSource.Text.Trim)
.FileName = txtResult.Text.Trim
End With
pRun.Start()
' Wait for it to finish
pRun.WaitForExit()
Catch ex As Exception
Debug.Print(ex.Message)
End Try
End Sub
兩點('..')表示一個目錄級別比當前更高。一個點('.')表示當前目錄。 – TnTinMn
在此示例中,C:\ Windows \ notepad.exe是比C:\ Windows \ System32更高的一個目錄級別。 –