Member Avatar for Huntondoom
Huntondoom

Do you have to clean up and sort your computer files?
But do you rather want to play some game and not sort everything out.
Well then here is something for you:
Clean Up! The Application for sorting en cleaning up your Directory's

Just give the directory you want to clean up and then it will give you a list of
extensions and Filename which you can use to suggest what it should do with it

But Huntondoom, if I have to suggest every time I want to clean up, isn't it better then to just clean it up normally?
No Fear Lazy person! Cause this application learns from you!
For every thing you have suggested will be memorized and used for later so
eventually you won't have to suggest again!

Screenshot:
[IMG]http://i51.tinypic.com/s6hqa9.gif[/img]

Information (less Commercial like):
Clean up is an Application that cleans and sort directory out.
You give the directory to clean out,
and it will give you a list of Extension and Filename
(Ps: in Filename list you can either say completely remove/move the file or you can remove/move files that contains a certain phrase / word / character)
Then you can use (in the Column "Action") these next commands:
- Move
- Delete
- Nothing

Move:
Suggested that you use the button in the last column to browser
Lets you move a File that contains a certain title or Extension to a new location

Delete:
Delete file that contains a certain title or Extension

Nothing:
Leave the File alone.
(Extension / Filename with nothing will be removed from the list, and the suggestion will be saved

Every suggestion will be saved and automatically filled in next time, it appears
It saves only recent action, so it overrides old suggest of that type of extension or filename (Filename will be added in automatically, not filled in)

Download: Clean Up 1.2.rar

Code:

Imports System.IO

Public Class CleanUp
    Public ExtensionActionList, FileNameActionlist As New List(Of String)
    Public IsFreakingBusy As Boolean = True
    'Filter
    Private Sub Main_load() Handles Me.Load
        Dim Path As String = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)
        If Directory.Exists(Path & "\Huntondoom") = False Then Directory.CreateDirectory(Path & "\Huntondoom")
        If File.Exists(Path & "\Huntondoom\CleanupELib.txt") = True Then
            Dim reader As StreamReader
            reader = New StreamReader(Path & "\Huntondoom\CleanupELib.txt")
            Do Until reader.Peek = -1
                ExtensionActionList.Add(reader.ReadLine)
            Loop
            reader.Close()
        Else
            My.Computer.FileSystem.WriteAllText(Path & "\Huntondoom\CleanupELib.txt", "", True)
        End If
        If File.Exists(Path & "\Huntondoom\CleanupFLib.txt") = True Then
            Dim reader As StreamReader
            reader = New StreamReader(Path & "\Huntondoom\CleanupFLib.txt")
            Do Until reader.Peek = -1
                FileNameActionlist.Add(reader.ReadLine)
            Loop
            reader.Close()
            IsFreakingBusy = True
            For I As Integer = 0 To FileNameActionlist.Count - 1
                Dim split() As String = FileNameActionlist(I).Split(",")
                Try
                    FGV.Rows.Add(split(0), split(1), split(2), "Browser")
                Catch
                End Try
            Next
            IsFreakingBusy = False
        Else
            My.Computer.FileSystem.WriteAllText(Path & "\Huntondoom\CleanupFLib.txt", "", True)
        End If
        IsFreakingBusy = False
    End Sub
    Private Sub Main_Close() Handles Me.FormClosed
        Dim Path As String = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)
        CheckExtension()
        Dim Content As String = ""
        For I As Integer = 0 To ExtensionActionList.Count - 1
            Content &= ExtensionActionList(I) & vbNewLine
        Next
        Dim Writer As StreamWriter
        Writer = New StreamWriter(Path & "\Huntondoom\CleanupELib.txt")
        Writer.Write(Content)
        Writer.Close()
        Content = ""
        For I As Integer = 0 To FileNameActionlist.Count - 1
            Content &= FileNameActionlist(I) & vbNewLine
        Next
        Writer = New StreamWriter(Path & "\Huntondoom\CleanupFLib.txt")
        Writer.Write(Content)
        Writer.Close()
    End Sub
    'Get Directory
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If FBD.ShowDialog = Windows.Forms.DialogResult.OK Then
            TextBox1.Text = FBD.SelectedPath
            DirectoryThing()
        End If
        ProgressBar1.Value = 0
        CheckExtension()
        EGVContentCheck()
        FGVContentCheck()
        IsFreakingBusy = False
    End Sub
    'Clean UP

    Private Sub StartCleaningToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StartCleaningToolStripMenuItem.Click
        Dim Time As Date = Date.Now
        Dim Nofp As Double
        CheckExtension()
        IsFreakingBusy = True
        For I As Integer = 0 To EGV.RowCount - 1
            If EGV.Rows(I).Cells(1).Value <> "" Then EGV.Rows(I).Cells(1).Value = SetHeadCapital(EGV.Rows(I).Cells(1).Value)
        Next
        For I As Integer = 0 To FGV.RowCount - 1
            If FGV.Rows(I).Cells(1).Value <> "" Then FGV.Rows(I).Cells(1).Value = SetHeadCapital(FGV.Rows(I).Cells(1).Value)
        Next
        Dim CleanUpPath As String = TextBox1.Text
        If CheckDir(CleanUpPath) = False Then
            MsgBox("Illegal Path")
            IsFreakingBusy = False
            Exit Sub
        End If
        'FileNames
        Dim Files() As String = Directory.GetFiles(CleanUpPath)
        Nofp = UBound(Files)
        With ProgressBar1
            .Maximum = UBound(Files)
            .Minimum = 0
            .Value = 0
        End With
        For I As Integer = 0 To UBound(Files)
            ProgressBar1.Value = I
            Dim AFile = Files(I)
            For J As Integer = 0 To FGV.RowCount - 1
                If FGV.Rows(J).Cells(0).Value <> "" Then
                    If AFile.ToLower.Contains(FGV.Rows(J).Cells(0).Value.ToString.ToLower) Then
                        If FGV.Rows(J).Cells(1).Value = "Move" And CheckDir(FGV.Rows(J).Cells(2).Value) Then
                            Dim Filename() As String = AFile.Split("\")
                            Try
                                File.Move(AFile, FGV.Rows(I).Cells(2).Value.ToString & "\" & Filename(UBound(Filename)))
                            Catch
                            End Try
                        End If
                        If FGV.Rows(J).Cells(1).Value = "Delete" Then
                            File.Delete(AFile)
                        End If
                    End If
                End If
            Next
        Next
        'Extensions
        Files = Directory.GetFiles(CleanUpPath)
        With ProgressBar1
            .Maximum = UBound(Files)
            .Minimum = 0
            .Value = 0
        End With
        Dim Index As Integer = 0
        For Each FileA As String In Files
            Dim Split() As String = FileA.Split(".")
            Dim Ext As String
            If UBound(Split) <> 0 Then Ext = Split(1)
            ProgressBar1.Value = Index
            Index += 1
            For I As Integer = 0 To EGV.Rows.Count - 1
                If EGV.Rows.Count <= I Then Exit For
                If EGV.Rows(I).Cells(0).Value <> "" Then
                    If (EGV.Rows(I).Cells(0).Value.ToString.Contains(Ext.ToString)) Then
                        If (EGV.Rows(I).Cells(1).Value <> "") Then
                            If (Not (EGV.Rows(I).Cells(1).Value = "Nothing")) Then
                                If EGV.Rows(I).Cells(1).Value = "Delete" Then
                                    Try
                                        File.Delete(FileA)
                                    Catch
                                    End Try
                                End If
                                If EGV.Rows(I).Cells(1).Value = "Move" And CheckDir(EGV.Rows(I).Cells(2).Value) Then
                                    Dim Filename() As String = FileA.Split("\")
                                    Try
                                        File.Move(FileA, EGV.Rows(I).Cells(2).Value & "\" & Filename(UBound(Filename)))
                                    Catch
                                    End Try
                                End If
                            End If
                        End If
                    End If
                End If
            Next
        Next
        IsFreakingBusy = False
        'results
        Files = Directory.GetFiles(CleanUpPath)
        Nofp -= UBound(Files)
        DirectoryThing()
        ProgressBar1.Value = 0
        Dim ts As TimeSpan = Date.Now - Time
        MsgBox("Time Taken: " & ts.TotalMinutes.ToString & " minutes" & vbNewLine _
               & "Number of Files moved: " & Nofp.ToString)
    End Sub
    'Gridview Extensions
    Private Sub EGV_CellContentChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles EGV.CellValueChanged
        If IsFreakingBusy = False Then
            If e.RowIndex < EGV.RowCount And e.RowIndex >= 0 Then
                If CheckDir(EGV.Rows(e.RowIndex).Cells(2).Value) = False Then
                    EGV.Rows(e.RowIndex).Cells(2).Value = ""
                End If
                EGVContentCheck()
            End If
        End If
    End Sub
    Private Sub EGV_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles EGV.CellContentClick
        If e.ColumnIndex = 3 Then
            IsFreakingBusy = True
            Dim Index As Integer = e.RowIndex
            If FBD.ShowDialog() = Windows.Forms.DialogResult.OK Then
                EGV.Rows(Index).Cells(1).Value = "Move"
                EGV.Rows(Index).Cells(2).Value = FBD.SelectedPath
            End If
            IsFreakingBusy = False
        End If
    End Sub
    'Gridview File name
    Private Sub FGV_RowCreated() Handles FGV.RowsAdded
        If IsFreakingBusy = False Then
            If FGV.RowCount >= 1 Then
                FGV.Rows(FGV.RowCount - 1).Cells(3).Value = "Browser"
            End If
        End If
    End Sub
    Private Sub FGV_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles FGV.CellContentClick
        If e.ColumnIndex = 3 Then
            IsFreakingBusy = True
            If FBD.ShowDialog() = Windows.Forms.DialogResult.OK Then
                FGV.Rows(e.RowIndex).Cells(1).Value = "Move"
                FGV.Rows(e.RowIndex).Cells(2).Value = FBD.SelectedPath
            End If
            IsFreakingBusy = False
        End If
    End Sub
    Private Sub FGV_CellContentChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles FGV.CellValueChanged
        If IsFreakingBusy = False Then
            If e.RowIndex <> -1 Then
                If CheckDir(FGV.Rows(e.RowIndex).Cells(2).Value) = False Then
                    FGV.Rows(e.RowIndex).Cells(2).Value = ""
                End If
                FGVContentCheck()
            End If
        End If
    End Sub
    'See Suggetions
    Private Sub SeeActionsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SeeActionsToolStripMenuItem.Click
        Suggestions.Show()
    End Sub
    'Functions
    '   Path
    Function CheckDir(ByVal DirectoryPath As String) As Boolean
        If DirectoryPath <> Nothing Then
            If Directory.Exists(DirectoryPath) = True Then
                Return True
            Else
                Return False
            End If
        Else
            Return False
        End If
    End Function
    Function DirectoryThing()
        IsFreakingBusy = True
        Dim Temp As New DataGridView
        FGV.Rows.Clear()
        EGV.Rows.Clear()
        Temp = EGV
        Dim Files() As String = Directory.GetFiles(TextBox1.Text)
        If UBound(Files) = -1 Then
            IsFreakingBusy = False
            Exit Function
        End If
        ProgressBar1.Maximum = UBound(Files)
        ProgressBar1.Minimum = 0
        For I As Integer = 0 To UBound(Files)
            ProgressBar1.Value = I
            Dim aFile As String = Files(I)
            Dim split() As String = aFile.Split("\")
            Dim Filename As String = split(UBound(split))
            FGV.Rows.Add(Filename, "", "", "Browser")
            Dim sp() As String = aFile.Split(".")
            Dim extenions As String = sp(UBound(sp))
            Dim Isin As Boolean = False
            If Temp.Rows.Count > 0 Then
                For J As Integer = 0 To Temp.Rows.Count - 1
                    If Temp.Rows(J).Cells(0).Value = extenions Then Isin = True
                Next
            End If
            If Isin = False And extenions.Length < 20 Then
                Temp.Rows.Add(extenions, "", "", "Browser")
            End If
        Next
        For I As Integer = 0 To Temp.Rows.Count - 1
            For J As Integer = 0 To ExtensionActionList.Count - 1
                Try
                    If ExtensionActionList(J).Contains(Temp.Rows(I).Cells(0).Value) = True Then
                        Dim split() As String = ExtensionActionList(J).Split(",")
                        For k As Integer = 0 To UBound(split)
                            Temp.Rows(I).Cells(k).Value = split(k)
                        Next
                    End If
                Catch
                End Try
            Next
        Next
        EGV = Temp
        For I As Integer = 0 To FileNameActionlist.Count - 1
            Dim split() As String = FileNameActionlist(I).Split(",")
            Try
                FGV.Rows.Add(split(0), split(1), split(2), "Browser")
            Catch
            End Try
        Next
    End Function
    '   Extension
    Function WriteExtension(ByVal ExtensionString As String, ByVal Action As String, ByVal Path As String)
        If Action <> "" Then
            For I As Integer = 0 To ExtensionActionList.Count - 1
                If I >= ExtensionActionList.Count Then Exit For
                If ExtensionActionList(I).Contains(ExtensionString) = True Then
                    ExtensionActionList.RemoveAt(I)
                End If
            Next
            ExtensionActionList.Add(ExtensionString & "," & Action & "," & Path)
        End If
    End Function
    Function CheckExtension()
        For I As Integer = 0 To EGV.Rows.Count - 1
            WriteExtension(EGV.Rows(I).Cells(0).Value, EGV.Rows(I).Cells(1).Value, EGV.Rows(I).Cells(2).Value)
        Next
        For I As Integer = 0 To FGV.Rows.Count - 1
            WriteFilename(FGV.Rows(I).Cells(0).Value, FGV.Rows(I).Cells(1).Value, FGV.Rows(I).Cells(2).Value)
        Next
    End Function
    Function EGVContentCheck()
        For I As Integer = 0 To EGV.Rows.Count - 1
            If I >= EGV.Rows.Count Then Exit Function
            Dim Cell As String = EGV.Rows(I).Cells(1).Value
            If Cell = "Nothing" Then
                WriteExtension(EGV.Rows(I).Cells(0).Value, EGV.Rows(I).Cells(1).Value, EGV.Rows(I).Cells(2).Value)
            End If
            If Cell = "Move" Then EGV.Rows(I).Cells(3).Value = "Browser"
            If Cell = "Move" Then
                If TextBox1.Text.Contains(EGV.Rows(I).Cells(2).Value.ToString) Then
                    EGV.Rows.RemoveAt(I)
                End If
            End If
        Next

    End Function
    '   FileName
    Function FGVContentCheck()
        For I As Integer = 0 To FGV.Rows.Count - 1
            If I >= FGV.Rows.Count Then Exit Function
            Dim Cell As String = FGV.Rows(I).Cells(1).Value
            If Cell = "Nothing" Then
                WriteFileName(FGV.Rows(I).Cells(0).Value, FGV.Rows(I).Cells(1).Value, FGV.Rows(I).Cells(2).Value)
                FGV.Rows.RemoveAt(I)
            End If
            If Cell = "Move" Then FGV.Rows(I).Cells(3).Value = "Browser"
            If Cell = "Move" Then
                If TextBox1.Text = FGV.Rows(I).Cells(2).Value.ToString Then
                    FGV.Rows.RemoveAt(I)
                End If
            End If
        Next

    End Function
    Function WriteFileName(ByVal FileName As String, ByVal Action As String, Optional ByVal Path As String = "")
        If Action <> "" Then
            For I As Integer = 0 To FileNameActionlist.Count - 1
                If I >= FileNameActionlist.Count Then Exit For
                If FileNameActionlist(I).Contains(FileName) Then FileNameActionlist.RemoveAt(I)
            Next
            FileNameActionlist.Add(FileName & "," & Action & "," & Path)
        End If
    End Function
    '   String
    Function SetHeadCapital(ByVal Text As String) As String
        Dim FirstLetter As String = Text(0)
        Dim Rest As String = Text.Remove(0, 1)
        Text = FirstLetter.ToUpper & Rest.ToLower
        Return Text
    End Function

    'Handeling
    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        StartCleaningToolStripMenuItem.Enabled = (TextBox1.Text.Length <> 0)
    End Sub
    Private Sub Form1_resize() Handles Me.Resize
        If Me.Visible = True Then
            Dim Wid As Integer
            If EGV.Width = FGV.Width Then
                Wid = Math.Round((EGV.Width / 4) - 1)
            Else
                If EGV.Width > FGV.Width Then
                    Wid = Math.Round((EGV.Width / 4) - 1)
                Else
                    Wid = Math.Round((FGV.Width / 4) - 1)
                End If
            End If
            For I As Integer = 0 To 3
                EGV.Columns(I).Width = Wid
                FGV.Columns(I).Width = Wid
            Next
        End If
    End Sub
End Class