0

I want to delete the entire folder or directory along with files and folders contained in it. How can I implement in C#?

Brian Tompsett - 汤莱恩
  • 5,438
  • 68
  • 55
  • 126
user1509
  • 1,131
  • 5
  • 17
  • 44

3 Answers3

5

Try using

Directory.Delete(dir_path, true);

Check manual

Marco
  • 55,302
  • 13
  • 128
  • 150
  • @Default: thanks, I didn't see I had italian page (but "as original", so in English !!) – Marco May 24 '12 at 07:16
1

Since it is tagges c# I assume the directory is at server side.Refer this link

How to delete all files and folders in a directory?

Community
  • 1
  • 1
Krishnanunni Jeevan
  • 1,699
  • 1
  • 15
  • 24
1
var dInfo = new DirectoryInfo("your_path_to_dir");
dInfo.Delete(true);

The true parameter in the Delete method is Recursive = true. This tells the method to delete the current folder and everything inside it. Files and folders.

st_stefanov
  • 1,062
  • 1
  • 8
  • 26