C# Directory Delete(String, Boolean)
Description
Directory Delete(String, Boolean)
Deletes the specified
directory and, if indicated, any subdirectories and files in the directory.
Syntax
Directory.Delete(String, Boolean)
has the following syntax.
public static void Delete(
string path,
bool recursive
)
Parameters
Directory.Delete(String, Boolean)
has the following parameters.
path
- The name of the directory to remove.recursive
- true to remove directories, subdirectories, and files in path; otherwise, false.
Returns
Directory.Delete(String, Boolean)
method returns
Example
The following example shows how to create a new directory, subdirectory, and file in the subdirectory, and then recursively delete all the new items.
using System;/* ww w . j av a 2 s. c om*/
using System.IO;
class Program
{
static void Main(string[] args)
{
string topPath = @"C:\NewDirectory";
string subPath = @"C:\NewDirectory\NewSubDirectory";
Directory.CreateDirectory(subPath);
Directory.Delete(topPath, true);
Console.WriteLine(Directory.Exists(topPath));
}
}
The code above generates the following result.