Recursive delete files and folders using C#

This function will Recursively delete all files and folders.

private void DeleteAllFiles(string sPath)
{
    foreach(string strFile in Directory.GetFiles(sPath))
    {
        File.Delete(strFile);
    }
    foreach (string strDir in Directory.GetDirectories(sPath))
    {
        DeleteAllFiles(strDir);
    }
    Directory.Delete(sPath);
}
This entry was posted in C#.

Leave a Reply

Your email address will not be published. Required fields are marked *