C# Directory Methods

Beginner
6 min read
Updated: Nov 2026
15 method guides
Method index

About This Index

This page is the C# Directory Methods index. Each row links to a full guide with syntax, parameters, return value, three examples, and FAQs. All examples use a small demo folder inside Path.GetTempPath(), remove it at the end, and print only leaf names or true and false facts, so the output you see is the output you get.

Learn what the Directory class is for on /c-sharp/directory. Use this page when you need a specific API such as CreateDirectory(), GetFiles(), or Exists().

Order is not promised.

The Get and Enumerate methods return paths in the order the file system chooses. Sort the names (for example with Array.Sort(items, StringComparer.Ordinal)) before you print or compare them. Also be careful with Delete(path, true): it removes a folder and everything inside it, with no undo.

How to Call a Directory Method

Every Directory method is static, so you call it on the class name. Add using System.IO; at the top of the file:

C#
string folder = Path.Combine(Path.GetTempPath(), "codetofun-demo");

Directory.CreateDirectory(folder);                    // make it (safe to repeat)
bool there = Directory.Exists(folder);                // check it
string[] files = Directory.GetFiles(folder, "*.txt"); // list files into an array
foreach (string d in Directory.EnumerateDirectories(folder)) { }  // stream subfolders
Directory.Delete(folder, true);                       // remove it and its contents

C# Directory Methods Table

All method guides in this C# tutorial series (15 tutorials), grouped by purpose.

Create / delete / move

3 methods

Make new folders, remove folders, and move or rename a folder. Delete asks for the recursive option before it removes a folder that has contents.

MethodDescriptionTutorial
CreateDirectory()Create a folder and every missing parent folder in one call; safe to repeat.Try it
Delete()Remove a folder, either an empty one or a whole tree with the recursive option.Try it
Move()Move or rename a folder together with everything inside it.Try it

Check

1 method

Ask whether a folder is really there. Exists never throws; it returns false for files, bad paths, and no permission.

MethodDescriptionTutorial
Exists()Check whether a folder exists; returns false for files, bad paths, and no permission.Try it

List (arrays)

3 methods

Read subfolders, files, or both into a string array. You get Length and indexes, but the whole array is built before the call returns.

MethodDescriptionTutorial
GetDirectories()Get the paths of subfolders as a string array you can sort, count, and index.Try it
GetFiles()Get the paths of files as a string array, with an optional pattern such as *.txt.Try it
GetFileSystemEntries()Get files and subfolders together as one string array.Try it

List (lazy)

3 methods

Stream paths one at a time while the folder is read. Best for huge folders, or when you may stop early.

MethodDescriptionTutorial
EnumerateDirectories()Stream subfolder paths one at a time without loading them all first.Try it
EnumerateFiles()Stream file paths one at a time, with an optional pattern such as *.txt.Try it
EnumerateFileSystemEntries()Stream files and subfolders together in one lazy sequence.Try it

Paths / location

5 methods

Read or change the working directory, find the root and parent of a path, and list the drives of the computer.

MethodDescriptionTutorial
GetCurrentDirectory()Read the folder the program is working in; relative paths start from here.Try it
SetCurrentDirectory()Change the working directory for the whole program; relative paths follow it.Try it
GetDirectoryRoot()Get the root of a path, such as C:\ or /, without touching the disk.Try it
GetParent()Get the parent folder of a path as a DirectoryInfo; null for a root.Try it
GetLogicalDrives()List the drive roots on this computer, such as C:\ and D:\.Try it

Frequently Asked Questions

They are the static methods of System.IO.Directory. They create, delete, move, check, and list folders, and they read or change the working directory, the parent of a path, the root of a path, and the drives of the computer.
This index lists 15 guides: CreateDirectory, Delete, Move, Exists, GetDirectories, GetFiles, GetFileSystemEntries, the three Enumerate methods, GetCurrentDirectory, SetCurrentDirectory, GetDirectoryRoot, GetParent, and GetLogicalDrives.
Get methods (GetFiles) return a finished string[] with Length and indexes. Enumerate methods (EnumerateFiles) stream one path at a time, which is better for huge folders or when you may stop early. Neither promises an order, so sort before printing.
Yes. Every example works inside a demo folder in Path.GetTempPath(), creates what it needs, and deletes its own folder at the end. Output never prints machine-specific absolute paths.
Read the C# Directory hub first. Then open CreateDirectory(), Exists(), GetFiles(), and Delete() from the tables below.

Start with CreateDirectory()

Make your first folder, including every missing parent, in one safe call.

CreateDirectory() 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.

12 people found this page helpful