string tempfolder = ("C:\\Users\\Administrator\\AppData\\Local\\Temp");
string[] tempfiles = Directory.GetFiles(tempfolder, "*.*", SearchOption.AllDirectories);
foreach (string filePath in Directory.GetFiles(tempfolder, "*.*", SearchOption.AllDirectories))
{
try
{
FileInfo currentFile = new FileInfo(filePath);
currentFile.Delete();
}
catch (Exception ex)
{
Debug.WriteLine("Error on file: {0}\r\n {1}", filePath, ex.Message);
}
}