The DirectoryInfo
class provides instance methods for creating, moving, and enumerating through directories and subdirectories.
Namespace: System.IO
Assembly: System.Runtime.dll
The DirectoryInfo
class provides instance methods for creating, moving, and enumerating through directories and subdirectories.
Namespace: System.IO
Assembly: System.Runtime.dll
Signature | Summary |
---|---|
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). |
Property | Type | Summary |
---|---|---|
FullName | string | Gets the full path of the directory. |
Name | string | Gets the name of this directory. |
Parent | DirectoryInfo | Gets the parent directory. |
Exists | bool | Indicates whether the directory exists. |
Attributes | FileAttributes | Gets or sets the attributes of the directory. |
CreationTime | DateTime | Gets or sets the creation time of the directory. |
LastAccessTime | DateTime | Gets or sets the last access time. |
LastWriteTime | DateTime | Gets or sets the last write time. |
Signature | Summary |
---|---|
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. |
// 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
.