I want to delete the entire folder or directory along with files and folders contained in it. How can I implement in C#?
Asked
Active
Viewed 487 times
1
-
You tagged asp.net. Then Delete on client-side or server-side? – Nikhil Agrawal May 24 '12 at 06:49
3 Answers
6
-
@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

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
-
-
@coder311: `Path` is the directory full path, the one I called `dir_path` – Marco May 24 '12 at 06:59
-
1Your code works, but getting `DirectoryInfo` just to delete a folder is cpu-wasting ;) – Marco May 24 '12 at 07:02
-
Thanks for your comment. And it depends, if he had performed some other action before delete. May be he needd to check some conditions before that... – st_stefanov May 24 '12 at 07:06