public static String DeleteDirectory(string directory)
{
if (H3Text.FixNull(directory).ToString().Length < 1)
{
return ("You did not specify a directory to delete.");
}
else
{
try
{
string webdir = H3Storage.MapPath(directory);
string dirObject = String.Format("win32_Directory.Name='{0}'", webdir);
using (ManagementObject dir = new ManagementObject(dirObject))
{
dir.Get();
ManagementBaseObject outParams = dir.InvokeMethod("Delete", null, null);
}
}
catch(DirectoryNotFoundException)
{
return ("The directory \"" + directory + "\" does not exist.");
}
catch(PathTooLongException)
{
return ("The directory \"" + directory.ToString().Substring(1, 80) + "...\" is too long and exceeds the system-defined maximum length for a directory name.");
}
catch(Exception e)
{
return ("Cannot delete the directory due to the following exception:<pre>\r\n" + e + "<pre>");
}
return (string.Empty);
}
}