Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
public static void DeleteDirectory(string path, bool throwExceptions = false)
{
try
{
if (Directory.Exists(path))
{
DirectoryInfo directory = new DirectoryInfo(path);
foreach (FileInfo file in directory.GetFiles())
{
try
{
file.Delete();
}
catch (Exception ex)
{
if (throwExceptions)
{
throw ex;
}
}
}
foreach (DirectoryInfo subdirectory in directory.GetDirectories())
{
try
{
Directory.Delete(subdirectory.FullName, true);
}
catch (Exception ex)
{
if (throwExceptions)
{
throw ex;
}
}
}
try
{
Directory.Delete(path);
}
catch (Exception ex)
{
if (throwExceptions)
{
throw ex;
}
}
}
}
catch (Exception ex)
{
if (throwExceptions)
{
throw ex;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.