This article has been excerpted from book "The Complete Visual C# Programmer's Guide" from the Authors of C# Corner.
The Directory and DirectoryInfo classes are used to perform various operations on directories such as Create, Move, Delete, and Enumerate. The functional distinction between these classes is the same as that between the File and FileInfo classes: the Directory class provides static methods whereas the DirectoryInfo class provides instance methods to deal with directories. Below, Table 6.2 compares these directory classes.
Table 6.2: Directory and DirectoryInfo class members
Like the FileInfo class, the DirectoryInfo class also has a single constructor that takes either the full path or relative path to the directory as the input parameter:
DirectoryInfo d1 = new DirectoryInfo(@"c:\temp"); //Make a directory object
Some important properties of the DirectoryInfo class, such as CreationTime, Exists, FullName, LastAccessTime, LastWriteTime, Name, Parent, and Root, work as their names suggest. For example, CreationTime shows the creation time of the directory. FullName is the full qualified path of the directory, while Name is just the relative folder name without the path (e.g., a directory with the FullName of c:\My Project\test would have a Name of test).
Hope this article would have helped you in understanding Directory and DirectoryInfo Classes in C#. See other articles on the website on .NET and C#.
| ||The Complete Visual C# Programmer's Guide covers most of the major components that make up C# and the .net environment. The book is geared toward the intermediate programmer, but contains enough material to satisfy the advanced developer.|