Hi,
Are this code:
var dir = new DirectoryInfo(viewDeviceItem.Path);
dir.Delete(true);
Equivalent to:
using System;
using System.IO;
class Program
{
static void Main()
{
string directoryPath = @"C:\path\to\your\directory"; // Specify your directory path here
try
{
// Delete all files in the directory
foreach (var file in Directory.EnumerateFiles(directoryPath))
{
File.Delete(file);
}
// Delete all subdirectories in the directory
foreach (var subDirectory in Directory.EnumerateDirectories(directoryPath))
{
Directory.Delete(subDirectory, true); // true to delete subdirectories and files inside them
}
// Delete the directory itself
Directory.Delete(directoryPath, false); // false because we’ve already deleted the contents
Console.WriteLine("Directory and its contents have been deleted.");
}
catch (Exception ex)
{
Console.WriteLine($"An error occurred: {ex.Message}");
}
}
}