The System.IO.Directory class is used for directory manipulation. This class provides static methods for creating, copying, moving, and deleting directories and sub directories.To use this class we should import System.IO namespace first.
The Directory.CreateDirectory method is used to creates a directory and sub directory in the specified path.
The Directory.Delete method is used to delete a directory. But If a directory has sub directories and/or files, you must delete them before you can delete a directory. If you try to delete a file that is not empty, you will get an error message.
Check directory is Exists:
The Directory.Exists method is used to check whether the directory is exists in the specified path. It returns boolean value.
The below code checks whether rootFolder is exists in E drive. If it exists then it will delete that folder. Else it will create the folder.
string root = @”E:rootFolder”;
Do you like this article? Help us to improve. Please post your comments below.