.NET API Reference

System.IO.DirectoryInfo Class

The DirectoryInfo class provides instance methods for creating, moving, and enumerating through directories and subdirectories.

Namespace: System.IO

Assembly: System.Runtime.dll

Constructors

SignatureSummary
DirectoryInfo(string path)Initializes a new instance of the DirectoryInfo class on the specified path.
DirectoryInfo(string path, bool checkHost)Initializes a new instance with a path and optional host check (internal use).

Properties

PropertyTypeSummary
FullNamestringGets the full path of the directory.
NamestringGets the name of this directory.
ParentDirectoryInfoGets the parent directory.
ExistsboolIndicates whether the directory exists.
AttributesFileAttributesGets or sets the attributes of the directory.
CreationTimeDateTimeGets or sets the creation time of the directory.
LastAccessTimeDateTimeGets or sets the last access time.
LastWriteTimeDateTimeGets or sets the last write time.

Methods

Instance Methods
Static Methods
SignatureSummary
DirectoryInfo Create()Creates the directory.
DirectoryInfo CreateSubdirectory(string path)Creates a subdirectory.
void Delete()Deletes the directory.
void Delete(bool recursive)Deletes the directory and optionally its contents.
DirectoryInfo[] GetDirectories()Gets an array of subdirectories.
FileInfo[] GetFiles()Gets an array of files within the directory.
DirectoryInfo MoveTo(string destDirName)Moves the directory to a new location.

Example

// Create a new folder and a subfolder
var root = new DirectoryInfo(@"C:\Temp\Demo");
if (!root.Exists) root.Create();

var sub = root.CreateSubdirectory("Logs");
Console.WriteLine($"Created: {sub.FullName}");

Static methods related to DirectoryInfo are provided by the Directory class rather than DirectoryInfo.

See Also