Q:

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

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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)

Note: In above program, we need to remember, when we use "Directory" class, System.IO namespace must be included in the program.

In this program, method is overloaded, to allow or deny recursive deletion.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# file handling (File class) solved programs/examples

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C# program to check given directory exists or not... >>
<< C# program to create directory...