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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.