Delete all files and directories in directory

/// <summary>
/// Deletes all files and folders in the targetDir
/// targetDir is not deleted, use with caution
/// </summary>
/// <param name="targetDir"></param>
/// <returns></returns>
public static void DeleteAllFilesAndFolder(String targetDir)
{
    System.IO.DirectoryInfo targetDirInfo = new DirectoryInfo(targetDir);

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


Datenschutzerklärung | Impressum