I want to clear the temporary Internet files folder completely. The location of the folder, e.g., C:\Users\Username\AppData\Local\Microsoft\Windows\Temporary Internet Files
, depends on the version of Windows, so it has to be dynamic.
use this path: Environment.SpecialFolder.InternetCache
string path = Environment.GetFolderPath(Environment.SpecialFolder.InternetCache);
//for deleting files
System.IO.DirectoryInfo di = new DirectoryInfo(path);
foreach (FileInfo file in di.GetFiles())
{
file.Delete();
}
foreach (DirectoryInfo dir in di.GetDirectories())
{
dir.Delete(true); //delete subdirectories and files
}