I want to delete the entire folder or directory along with files and folders contained in it. How can I implement in C#?
3 Answers
Since it is tagges c# I assume the directory is at server side.Refer this link
Comments
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.
4 Comments
user1509
Path is to be mentioned along with the directory name?
Marco
@coder311:
Path is the directory full path, the one I called dir_pathMarco
Your code works, but getting
DirectoryInfo just to delete a folder is cpu-wasting ;)st_stefanov
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...