Hi guys![]()
I have a problem and it is freakin me out for a week now.
I have made a programm with vb 2008 express that must clean the temp folder the temporary internet folder and the cookies folder.
But somehow it doesn't work,
I think that the problem is that ONE of the many files is used (by another programm) and when the programm comes to that file and it see that it's in use it just stop's cleaning up.
My code is:
Code:Function clean() On Error Resume Next Dim pathCache As String = Environment.GetFolderPath(Environment.SpecialFolder.InternetCache) My.Computer.FileSystem.DeleteDirectory(pathCache, FileIO.DeleteDirectoryOption.DeleteAllContents) Dim pathCookie As String = Environment.GetFolderPath(Environment.SpecialFolder.Cookies) My.Computer.FileSystem.DeleteDirectory(pathCookie, FileIO.DeleteDirectoryOption.DeleteAllContents) Dim pathTemp As String = Environment.GetFolderPath(Environment.SpecialFolder.Templates) My.Computer.FileSystem.DeleteDirectory(pathTemp, FileIO.DeleteDirectoryOption.DeleteAllContents) Return 0 End Function
And I also have this function I think this is the best one but this one has the same problem I think.
Code:Public Sub DelIECache() Dim di As New IO.DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache)) On Error Resume Next If di.Exists = False Then di.Create() End If System.IO.File.SetAttributes(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache).ToString, IO.FileAttributes.Normal) Dim Cache1 As String Dim Cache2() As String Cache2 = IO.Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache)) For Each Cache1 In Cache2 'Get all files in Temporary internet files, ‘folder and then set their attribute to normal, and then delete them. IO.File.SetAttributes(Cache1, IO.FileAttributes.Normal) IO.File.Delete(Cache1) Next For Each Cache1 In Cache2 'Get all files in Temporary internet files, ‘folder and then set their attribute to normal, and then delete them. IO.File.SetAttributes(Cache1, IO.FileAttributes.Normal) IO.File.Delete(Cache1) Next ' The true indicates that if subdirectories ' or files are in this directory, they are to be deleted as well. di.Delete(True) err: On Error Resume Next'///IGNORE ERROR/// End Sub
I need your help to make it work.
Please edit the code where needed or help me with a solution![]()
Already thanks alot![]()




Reply With Quote