Directory.GetCurrentDirectory Method ()


Gets the current working directory of the application.

Namespace:   System.IO
Assembly:  mscorlib (in mscorlib.dll)

Public Shared Function GetCurrentDirectory As String

Return Value

Type: System.String

A string that contains the path of the current working directory, and does not end with a backslash (\).

Exception Condition

The caller does not have the required permission.


The operating system is Windows CE, which does not have current directory functionality.

This method is available in the .NET Compact Framework, but is not currently supported.

The current directory is distinct from the original directory, which is the one from which the process was started.

For a list of common I/O tasks, see Common I/O Tasks.

The following example demonstrates how to use the GetCurrentDirectory method.

Imports System
Imports System.IO

Public Class Test
    Public Shared Sub Main()
            ' 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
            End If
            ' Change the current directory.
            Environment.CurrentDirectory = (target)
            If path.Equals(Directory.GetCurrentDirectory()) Then
                Console.WriteLine("You are in the temp directory.")
                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
    End Sub
End Class


for access to path information for the current directory. Associated enumeration: FileIOPermissionAccess.PathDiscovery

Universal Windows Platform
Available since 10
.NET Framework
Available since 1.1
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top