0

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

3
Contributors
2
Replies
4
Views
5 Years
Discussion Span
Last Post by Mitja Bonca
0

Do it like:

    System.IO.DirectoryInfo downloadedMessageInfo = new    DirectoryInfo(GetMessageDownloadFolderPath());

foreach (FileInfo file in downloadedMessageInfo.GetFiles())
{
    file.Delete(); 
}
foreach (DirectoryInfo dir in downloadedMessageInfo.GetDirectories())
{
    dir.Delete(true); 
}

or:

public void DeletingFilesAndFolders(DirectoryInfo directory)
{
    foreach(System.IO.FileInfo file in directory.GetFiles()) file.Delete();
    foreach(System.IO.DirectoryInfo subDirectory in directory.GetDirectories()) subDirectory.Delete(true);
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.