1

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,753
  • 72
  • 57
  • 129
user1509
  • 1,151
  • 5
  • 17
  • 45

3 Answers3

6

Try using

Directory.Delete(dir_path, true);

Check manual

Marco
  • 56,740
  • 14
  • 129
  • 152
  • @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,719
  • 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,147
  • 1
  • 10
  • 28