1

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

1
  • You tagged asp.net. Then Delete on client-side or server-side? Commented May 24, 2012 at 6:49

3 Answers 3

6

Try using

Directory.Delete(dir_path, true); 

Check manual

Sign up to request clarification or add additional context in comments.

1 Comment

@Default: thanks, I didn't see I had italian page (but "as original", so in English !!)
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?

Comments

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.

4 Comments

Path is to be mentioned along with the directory name?
@coder311: Path is the directory full path, the one I called dir_path
Your code works, but getting DirectoryInfo just to delete a folder is cpu-wasting ;)
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...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.