vb.net – Dealing with unwanted chrome cache data & visual studio log file


I am not sure this is the best way to deal with these unwanted files.
YES I wrote a small VB.Net application to delete chrome cache data files that have this format “f_00006a” & another file that shows up in a Temp folder every time I start my computer “dd_updateconfiuration_202.log” and
if my computer is idle for 10 min or more Visual Studio tries to update
and adds a bunch of these dd files to the temp folder REAL Annoying
YES I have VS 2019 and have it set to not request updates
Here is the code I wrote to deal with this feel free to offer suggestions
for improvements to this code. It works fine but seems like overkill to
deal with the situation.

Public Class frmStart
Public Sub frmStart_KeyPress(sender As Object, e As KeyPressEventArgs) Handles Me.KeyPress
    If Asc(e.KeyChar) = 27 Then
        Application.Exit()
    End If
End Sub

Private Sub btnVCache_Click(sender As Object, e As EventArgs) Handles btnVCache.Click

    lstFiles.Items.Clear()

    Dim folderPath As String = "C:\Users\Dwight\AppData\Local\Google\Chrome\User Data\Default\Cache\Cache_Data\"
    Process.Start(folderPath)
    'Me.WindowState = FormWindowState.Minimized

End Sub

Private Sub btnVTemp_Click(sender As Object, e As EventArgs) Handles btnVTemp.Click

    lstFiles.Items.Clear()

    Dim folderPath As String = "C:\Users\Dwight\AppData\Local\Temp\"
    Process.Start(folderPath)

End Sub

Private Sub btnDelCache_Click(sender As Object, e As EventArgs) Handles btnDelCache.Click

    Dim folderPath As String = "C:\Users\Dwight\AppData\Local\Google\Chrome\User Data\Default\Cache\Cache_Data\"
    Dim filePattern As String = "f*"
    Dim result As MsgBoxResult = Nothing
    Dim files As IEnumerable(Of String) = Directory.EnumerateFiles(folderPath, filePattern)

    lstFiles.Items.Clear() 'WORKS where to use it and HOW TO USE
    Try

        If files.Any() Then

            MsgBox("Files Found", vbOKOnly, "File Deletion")

            result = MsgBox("Yes to Delete Files" & vbCrLf & "NO ONLY View Files", vbYesNo, "File Deletion")

            If result = MsgBoxResult.Yes Then

                For Each fileName As String In Directory.GetFiles(folderPath)
                    Dim dirInfo As New DirectoryInfo(fileName)
                    Dim fC As String = fileName.Replace(folderPath, String.Empty)

                    If fC.Substring(0, 1) = "f" Then
                        lstFiles.Items.Add(fileName.Replace(folderPath, String.Empty))
                        My.Computer.FileSystem.DeleteFile(fileName, FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.SendToRecycleBin, FileIO.UICancelOption.ThrowException)
                    End If

                Next

                MsgBox("Files Deleted", vbOKOnly, "File Deletion")

            ElseIf result = MsgBoxResult.No Then

                Dim file As String = folderPath.Replace(folderPath, String.Empty)
                For Each file In files
                    Dim fileName As String = Path.GetFileName(file)
                    lstFiles.Items.Add(fileName)
                Next

            End If
            'Exit Sub
        Else
            MsgBox("NO Files With" & "   f   " & "FOUND", vbOKOnly, "File Deletion")

        End If
    Catch ex As UnauthorizedAccessException
        MessageBox.Show("Access to the folder is denied.")
    Catch ex As DirectoryNotFoundException
        MessageBox.Show("The specified folder does not exist.")
    Catch ex As Exception
        MessageBox.Show("An error occurred: " & ex.Message)
    End Try
End Sub

Private Sub btnDelTemp_Click(sender As Object, e As EventArgs) Handles btnDelTemp.Click

    Dim folderPath As String = "C:\Users\Dwight\AppData\Local\Temp\"
    Dim result As MsgBoxResult = Nothing
    ' Get all files in the folder that start with "dd"
    Dim files As String() = Directory.GetFiles(folderPath, "dd*")

    lstFiles.Items.Clear()

    ' Check if any files are found
    If files.Length = 0 Then
        result = MsgBox("No Files to Delete", vbOKOnly, "File Deletion")
        Exit Sub
    End If

    result = MsgBox("Yes to Delete Files" & vbCrLf & "NO to EXIT", vbYesNo, "File Deletion")
    If result = MsgBoxResult.Yes Then
        For Each file As String In files
            lstFiles.Items.Add(file.Replace(folderPath, String.Empty))
            ' Send file to recycle bin
            My.Computer.FileSystem.DeleteFile(file, FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.SendToRecycleBin, FileIO.UICancelOption.ThrowException)

        Next

        MsgBox("Files Deleted", vbOKOnly, "File Deletion")
    ElseIf result = MsgBoxResult.No Then
        MsgBox("NO Files DELETED", vbOKOnly, "File Deletion")
        Exit Sub
    End If
End Sub

Private Sub btnOpenRB_Click(sender As Object, e As EventArgs) Handles btnOpenRB.Click

    lstFiles.Items.Clear()

    Dim userSid As String = WindowsIdentity.GetCurrent().User.Value

    ' Construct the path to the Recycle Bin for the current user
    Dim recycleBinPath As String = String.Format("C:\$Recycle.Bin\{0}", userSid)

    ' Start a new process to open Windows Explorer at the Recycle Bin path
    Process.Start("explorer.exe", recycleBinPath)

End Sub

End Class

Leave a Reply

Your email address will not be published. Required fields are marked *