Open In App

C# Program to Get Complete Path of Current Directory

Given a directory, now our task is to find the path of the given directory or current directory. So to this task, we use the GetCurrentDirectory() method of the Directory class. This method will return the complete path of the current directory. The result given by this method will not end with a backslash (\).

Syntax:



public static string GetCurrentDirectory();

Return: It will return a string that represents the path of the current directory. 

Exception: It will throw the following exceptions:



Example:




// C# program to find the path of
// the current directory
using System;
using System.IO;
 
class GFG{
 
static void Main()
{
     
    // Finding the complete path of the current directory
    // Using GetCurrentDirectory() method
    Console.WriteLine("Current directory path: " +
                      Directory.GetCurrentDirectory());
}
}

Output:

Current directory path: C:\Users\Sravan\ConsoleApplication12
Article Tags :