Delete a folder even though it is with files

0

What code should I use to delete a folder in which it contains files inside it?

This code I used only deletes an empty folder.


void ApagarPasta(string nameOf, bool subPastas){
     Directory.Delete(nameOf, subPastas); // Deleta a pasta e subpastas vazias apenas.
}
    
asked by anonymous 03.08.2014 / 20:22

1 answer

1

The second parameter of the Delete method indicates whether subfolders / files should also be removed.

public static void Delete(
    string path,
    bool recursive
)

path Type: System.String
The name of the directory to be removed.

recursive Type: System.Boolean
true to remove directories, subdirectories, and files in path; otherwise, false.

Example:

System.IO.Directory.Delete("caminho da pasta", true);
    
03.08.2014 / 22:14