10-31-2011، 02:50 PM
کد:
private void EmptyCacheFolder(DirectoryInfo folder)
{
//loop through all the files in the folder provided
foreach (FileInfo file in folder.GetFiles())
{
file.Delete();
}
foreach (DirectoryInfo subfolder in folder.GetDirectories())
{
//recursively delete all files and folders in each sub directory
EmptyCacheFolder(subfolder);
}
}
public bool ClearCache()
{
//variable to hold our status
bool isEmpty;
try
{
//call EmptyCacheFolder passing the default internet cache
//folder
EmptyCacheFolder(new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache)));
isEmpty = true;
}
catch
{
isEmpty = false;
}
return isEmpty;
}