将当前路径分配给变量VB.net

时间:2015-10-19 21:51:24

标签: vb.net variables filepath

我有一个想法,但我不确定如何实现它。

Dim currentPath As String
    If System.IO.Path.Combine(Directory.GetCurrentDirectory(), "AccountServer.exe") OrElse System.IO.Path.Combine(Directory.GetCurrentDirectory(), "AccountServer.exe") Then

    End If

我想要的是我希望程序在当前文件中查找AccountServer.exe,如果程序没有找到它,那么它将查看AccountServer / AccountServer.exe。

如果找到该.exe的当前路径,则会将其分配给currentPath变量。

我将如何做到这一点,甚至可能?

1 个答案:

答案 0 :(得分:0)

您需要一些逻辑来查看文件是否存在:

        Dim currentPath As String = System.IO.Path.Combine(IO.Directory.GetCurrentDirectory(), "AccountServer.exe")
        If IO.File.Exists(currentPath) Then
            '...
        Else
            currentPath = System.IO.Path.Combine(IO.Directory.GetCurrentDirectory(), "AccountServer.exe")
            '...
        End If