If you want to write a. netCodeTo search for the Internet, you should be able to find such code:
VoidEmptycachefolder (directoryinfo folder)
{
Foreach(Fileinfo FileInFolder. getfiles ())
{
File. Delete ();
}
Foreach(Directoryinfo subfolderInFolder. getdirectories ())
{
Emptycachefolder (subfolder );
}
}
// Function which is used for clearing the cache
BoolSort AchE ()
{
BoolEmpty;
Try
{
Emptycachefolder (NewDirectoryinfo (environment. getfolderpath (environment. specialfolder. internetcache )));
Empty =True;
}
Catch
{
Empty =False;
}
ReturnEmpty;
}
But when you actually run this code, you find that there is no way to make the code run stably, and the files in the IE cache directory cannot be deleted. Why?
In this Code, when you try to delete files in the Temporary Internet Files directory, some files are system files or are being used by browsers, io exception will be thrown, and the entire foreach loop will be terminated.
First, we should put the code in try to ensure that the loop will not be terminated due to exception. Second, for files with IO conflicts that cannot be deleted, we should register it as automatic deletion at next startup, in this way, the IE cache files can be thoroughly removed.
For specific code, refer:
Your Internet Explorer's secrets