Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

delete a directory having subdirectory (not empty)

Tags:

c#

asp.net

vb.net

How can i delete a directory having subdirectory inside it which is not empty.

thanks for the answers

but now when am deleteing any directory at run time so it will take me to the login page.

like image 338
Vir Avatar asked May 09 '11 07:05

Vir


People also ask

How do I delete a directory and subdirectory?

To remove a directory and all its contents, including any subdirectories and files, use the rm command with the recursive option, -r . Directories that are removed with the rmdir command cannot be recovered, nor can directories and their contents removed with the rm -r command.

Can you remove delete a non empty directory using the command rmdir?

In Linux, whenever you want to delete a file, you'd use the rm command. When it comes to deleting a directory, however, things get a bit complex. To delete a directory, there's a dedicated tool rmdir that can remove empty directories.

How do you force rmdir?

rm command with -f , force option combined with -r as rm -rf option is used to force remove Linux directories. -r stands for recursive so that rm can remove all the sub-directories also. -r option is needed to remove a directory even if the directory is empty with no subdirectory or file in it.

What correct Linux command that will remove dir1 dir2 subdirectories?

There are two ways to remove directories in Linux: the rm and rmdir commands. The TL;DR of both commands is that rm deletes directories that may contain content such as files and subdirectories, while rmdir ONLY deletes empty directories.


1 Answers

You could use the Directory.Delete method passing true as second argument.

Directory.Delete(@"c:\somedirectory", true);
like image 193
Darin Dimitrov Avatar answered Oct 05 '22 16:10

Darin Dimitrov