How do I delete the entire folder/ directory?

2019-09-01 08:01发布

问题:

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

回答1:

Try using

Directory.Delete(dir_path, true);

Check manual



回答2:

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?



回答3:

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.