C# program to delete an empty and a non-empty directory

Syntax

void Directory.Delete(string path);
void Directory.Delete(string path, bool recursive);

Program

using System;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main()
        {
            Console.WriteLine("Delete Empty directory (Empty1)");
            Directory.Delete("D:/Empty1");

            Console.WriteLine("Delete Empty directory (Empty2)");
            Directory.Delete("D:/Empty2",false);

            Console.WriteLine("Delete Non-Empty directory (India)");
            Directory.Delete("D:/India",true);
        }
    }
}

Output

Delete Empty directory (Empty1)
Delete Empty directory (Empty2)
Delete Non-Empty directory (India)

Leave a Comment

error: Alert: Content is protected!!