2020年5月15日 星期五

vb.net console取得自身路徑 [Get EXE Path]


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
Imports System

Imports System.IO


Module Module1


    Sub Main()

        Try

            ' Get the current directory.

            Dim path As String = Directory.GetCurrentDirectory()

            Dim target As String = "c:\temp"

            Console.WriteLine("The current directory is {0}", path)

            If Directory.Exists(target) = False Then

                Directory.CreateDirectory(target)

            End If

            ' Change the current directory.

            Environment.CurrentDirectory = (target)

            If path.Equals(Directory.GetCurrentDirectory()) Then

                Console.WriteLine("You are in the temp directory.")

            Else

                Console.WriteLine("You are not in the temp directory.")

            End If

        Catch e As Exception

            Console.WriteLine("The process failed: {0}", e.ToString())

        End Try


        Console.Read()

    End Sub


End Module

沒有留言:

張貼留言