|
-
Mar 25th, 2006, 08:12 PM
#1
Thread Starter
Lively Member
Deleting Internet Explorer Temporary Files in C#
Can anyone tell me why this wont work? I got the right folder path but it will not remove the files in that folder.
Code:
DirectoryInfo di = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache));
foreach (FileInfo fl in di.GetFiles())
{
fl.Delete();
}
-
Mar 25th, 2006, 08:28 PM
#2
Re: Deleting Internet Explorer Temporary Files in C#
 Originally Posted by 2MuchRiceMakesMeSick
Can anyone tell me why this wont work? I got the right folder path but it will not remove the files in that folder.
Code:
DirectoryInfo di = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache));
foreach (FileInfo fl in di.GetFiles())
{
fl.Delete();
}
By doesn't work, what do you mean, just not deleting or throwing exceptions?
Bill
-
Mar 25th, 2006, 08:44 PM
#3
Thread Starter
Lively Member
Re: Deleting Internet Explorer Temporary Files in C#
it doesnt delete anything. no errors no exceptions
-
Mar 26th, 2006, 03:57 AM
#4
Re: Deleting Internet Explorer Temporary Files in C#
That folder requires some additional coding. Since index.dat amongst other files will not let you delete them, you have to take into account the access violations. There may be a quicker, cleaner method, but you can do this with recursive searching:
Code:
private void safeRecursiveDeleter(string path)
{
foreach (string FileName in Directory.GetFiles(path))
{
try
{
File.Delete(FileName);
}
catch { Exception ex; }//Certain files WILL give you access violations (index.dat)
}
foreach (string DirectoryName in Directory.GetDirectories(path))
{
safeRecursiveDeleter (DirectoryName);
try
{
Directory.Delete(DirectoryName, true); //Will kill the recursive search if there is no undeletable files
}
catch {Exception ex;}
}
}
//Called via:
safeRecursiveDeleter(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache));
Bill
-
Mar 26th, 2006, 11:59 AM
#5
Re: Deleting Internet Explorer Temporary Files in C#
I don't have enough expertise in C# to play with InterOp and APIs yet. 
I guess you can use the DeleteUrlCacheEntry API to do this. Here is a VB6 example. May be it woun't be hard to convert it in C#
Edit:
found a related page in MS Support pages. It may help ? http://support.microsoft.com/kb/326201/EN-US/
Last edited by iPrank; Mar 26th, 2006 at 12:05 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|