C# Directory GetCurrentDirectory() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
System.IO

Definition

In C#, Directory.GetCurrentDirectory() returns the current working directory: the folder your program treats as "here". Any relative path such as "data.txt" is resolved from this folder.

The value depends on how the program was started, not on where the .exe file sits. A program started from a terminal uses the terminal's folder, and one started from a shortcut can use a different folder.

This is a static method of System.IO.Directory. Call it as Directory.GetCurrentDirectory(...); there is no new Directory(). For an object that remembers one folder, see DirectoryInfo.

Syntax

The method takes no arguments and returns a path string.

C#
string cwd = Directory.GetCurrentDirectory();

Console.WriteLine(Path.IsPathRooted(cwd));
Console.WriteLine(Path.GetFileName(cwd));   // varies by machine
CallWhat it does
Directory.GetCurrentDirectory()Returns the full path of the working directory.
Environment.CurrentDirectoryA property that gives the same value (and can also set it).
AppContext.BaseDirectoryThe folder of the program files. It is not always the same as the working directory.

The result differs on every machine, so tutorial code should not print the full path. These examples print booleans or only the last folder name through Path.GetFileName, and the text says when a value varies.

Library declarations
C#
public static string GetCurrentDirectory();

Parameters

ParameterDescription
NoneGetCurrentDirectory() takes no parameters.

Return Value

Return ValueDescription
stringThe absolute path of the current working directory. A root folder ends with a separator (such as C:\); other folders do not.

C# Examples

Example 1 — Check the Working Directory Without Printing It

The path is different on each computer, so print facts about it instead.

C#
using System;
using System.IO;

class Program {
    static void Main() {
        string cwd = Directory.GetCurrentDirectory();

        Console.WriteLine(cwd.Length > 0);
        Console.WriteLine(Path.IsPathRooted(cwd));
        Console.WriteLine(Directory.Exists(cwd));
    }
}

How It Works

  1. Not empty. The method always returns text, so cwd.Length > 0 is True. Printing cwd itself would show a different path for each reader.
  2. An absolute path. Path.IsPathRooted is True because the result starts from a drive or from /, never from a relative piece such as ...
  3. A real folder. The working directory exists, so Directory.Exists is True.

Example 2 — See How a Relative Path Becomes Full

Compare Path.GetFullPath of a short name with the working directory plus that name.

C#
using System;
using System.IO;

class Program {
    static void Main() {
        string cwd = Directory.GetCurrentDirectory();

        string viaFullPath = Path.GetFullPath("notes.txt");
        string viaCombine = Path.Combine(cwd, "notes.txt");

        Console.WriteLine(viaFullPath == viaCombine);
        Console.WriteLine(Path.GetFileName(viaFullPath));
        Console.WriteLine(Path.IsPathRooted("notes.txt"));
    }
}

How It Works

  1. No file is touched. Both lines only work with text. The file notes.txt does not need to exist.
  2. Two ways, one answer. Path.GetFullPath adds the working directory in front of a relative name. Path.Combine(cwd, ...) does it by hand. They give the same text, so the comparison is True.
  3. The name stays the same. Only the folder part was added, so the last part is still notes.txt.
  4. A relative path is not rooted. "notes.txt" has no drive or leading slash, so IsPathRooted is False. This is why it needs a working directory.

Example 3 — Build a Path Under the Working Directory

Combine the folder with a name, then take the pieces apart again.

C#
using System;
using System.IO;

class Program {
    static void Main() {
        string cwd = Directory.GetCurrentDirectory();
        string reports = Path.Combine(cwd, "reports");

        Console.WriteLine(Directory.GetCurrentDirectory() == Environment.CurrentDirectory);
        Console.WriteLine(Path.GetFileName(reports));
        Console.WriteLine(Path.GetDirectoryName(reports) == cwd);
        Console.WriteLine(reports.StartsWith(cwd));
    }
}

How It Works

  1. Two spellings, one value. Environment.CurrentDirectory reads the same setting, so the comparison with GetCurrentDirectory() is True.
  2. Only text is built. Path.Combine joins the working directory and reports with the right separator. No folder is created.
  3. Take it apart. GetFileName gives reports, and GetDirectoryName gives back the working directory, so the third line is True.
  4. Still under the working directory. StartsWith(cwd) is True because the new path begins with the working directory. Real code would call CreateDirectory(reports) next if it needs the folder.

Frequently Asked Questions

The absolute path of the current working directory of the process. Relative paths, such as "data.txt", are resolved from this folder.
Not always. It depends on how the program was started. Use AppContext.BaseDirectory when you need the folder that holds your program files.
They return the same value. Environment.CurrentDirectory is a property you can also set, and Directory.GetCurrentDirectory() is the method form.
Because it differs on every computer. It is better to print facts such as Path.IsPathRooted(cwd), or only Path.GetFileName(cwd), and say that it varies.
Use Directory.SetCurrentDirectory(path). It changes the working directory for the whole program.

Next: GetDirectories()

Get the paths of subfolders as a string array you can sort, count, and index.

GetDirectories() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

13 people found this page helpful