Open In App

C# Program to Get the Full Path of the Current Directory Using Environment Class

In C#, Environment Class provides information about the current platform and manipulates, the current platform. It is useful for getting and setting various operating system-related information. We can use it in such a way that it retrieves command-line arguments information, exit codes information, environment variable settings information, contents of the call stack information, and time since the last system boot in milliseconds information. In this article, we will discuss how to get the full path of the current directory. So to solve this problem we use the CurrentDirectory property of the Environment Class. This property returns the complete path of the current working directory of your computer. This property also throws the following exceptions:

Syntax:



Environment.CurrentDirectory

Return Type: The return type of this property is a string. And the returned string represents the current directory path.



Example:




// C# program to find the current directory path
// Using Environment Class
using System;
  
class GFG{
      
static public void Main()
{
      
    // Declaring a string
    string resultPath = "";
      
    // Get the complete path of the current
    // working directory. Using 
    // CurrentDirectory property of 
    // Environment class
    resultPath = Environment.CurrentDirectory;
      
    Console.WriteLine("System Directory:\n" + resultPath);
}
}

Output:

System Directory:
/Users/Projects/newprogram/
Article Tags :
C#