0

Hi to all I'm writtting a small application, that one of its options will be delete Internet Temporary Files(Cache of IE).
I try deleting the files but without any success. I found an example of code in the web, but when I use the code I receive a error that I don't have the permissions.
This is the code I'm using, I hope you can help me

void ClearFolder(DirectoryInfo folder)
{
      foreach (FileInfo file in folder.GetFiles())
      { file.Delete(); }
      foreach (DirectoryInfo subfolder in folder.GetDirectories())
      { ClearFolder(subfolder); }
}

And call the method like:

ClearFolder(new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache)));

:'(
Thanks

2
Contributors
1
Reply
2
Views
10 Years
Discussion Span
Last Post by Ramy Mahrous
0

did u run this program as administrator, if you don't please run it as administrator
and modify your code to be

void ClearFolder(DirectoryInfo folder)
{
foreach (FileInfo file in folder.GetFiles())
{
try
{
file.Delete();
}
catch
{
}
}
foreach (DirectoryInfo subfolder in folder.GetDirectories())
{
ClearFolder(subfolder);
}
}

because there are some files won't be deleted as they are being used.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.