Internet Explorer Cleaning Tool in Visual Basic

Introduction: This tutorial is on how to create a temporary file cleaner for Internet Explorer in Visual Basic. Information: The path Internet Explorer currently uses for storing the temporary files and folders is; C:\Users\{User name}\AppData\Local\Microsoft\Windows\INetCache\IE Design: This form simply uses one button to delete the contents; we can keep its name the default 'button1' since it is the only component on the form. Of course, this button will begin the deletion process. Warning: Once the button is clicked we give the user a quick warning with a yes or no option to continue on to whether they would like to continue with the deletion process or not...
  1. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  2. Dim result As MsgBoxResult = MsgBox("Deleting these temporary files may affect your use of Internet Explorer, would you still like to continue?", MsgBoxStyle.YesNo, "Warning:")
  3. If (result = MsgBoxResult.Yes) Then
  4. 'Continue with deletion
  5. End If
  6. End Sub
Getting the Path: Next we want to get the logged in users username to get the full path to the temporary Internet Explorer files folder. To do this we use the Environment method and pass the value 'username'...
  1. Dim username As String = Environ("Username")
  2. Dim path As String = "C:\Users\" + username + "\AppData\Local\Microsoft\Windows\INetCache\IE"
Counting the Contents: Next we want to count how many total directories and files there are within the directory, we output the total before cleaning to the user...
  1. Dim preClean As Integer = 0
  2. preClean += My.Computer.FileSystem.GetFiles(path).Count()
  3. preClean += My.Computer.FileSystem.GetDirectories(path).Count()
  4. MsgBox("Total files and directories pre-cleaning: " + preClean.ToString())
Deleting the Contents: Next we iterate through each file and directory within the main directory of Internet Explorer and delete each one...
  1. For Each f As String In My.Computer.FileSystem.GetFiles(path)
  2. My.Computer.FileSystem.DeleteFile(f)
  3. Next
  4. For Each f As String In My.Computer.FileSystem.GetDirectories(path)
  5. My.Computer.FileSystem.DeleteDirectory(f, FileIO.DeleteDirectoryOption.DeleteAllContents)
  6. Next
Finally, Re-counting: Finally, we re-count the contents and output the comparison so the user can see how many were successfully deleted, it should be all of them...
  1. Dim afterClean As Integer = 0
  2. afterClean += My.Computer.FileSystem.GetFiles(path).Count()
  3. afterClean += My.Computer.FileSystem.GetDirectories(path).Count()
  4. MsgBox("Total files and directories pre-cleaning: " + preClean.ToString() + vbNewLine + "Total files and directories after-cleaning: " + afterClean.ToString() + vbNewLine + "Total deleted: " + (preClean - afterClean).ToString())
Exercise: Note; this program does not currently show the total number of files pre and after cleaning including the files within directories; as an extension, try to implement this. Hint: You must iterate through each of the directories.

Add new comment