You are on page 1of 14

FileCount = c FilePath = New ArrayList End Sub End Structure Private Sub frmRepeatedFiles_Load(ByVal sender As System.Object, ByVal e As System.

EventArgs) Handles MyBase.Load End Sub Sub GetFolders(ByRef d1 As String) Panel1.Controls.Clear() Application.DoEvents() ' Dim dr As DriveInfo ' dr = New DriveInfo(d1) 'If dr.IsReady = False Then Exit Sub Dim d As New DirectoryInfo(d1) ' Dim ltop As Integer = 20 Dim totalfolders As Integer = d.GetDirectories.Length Dim totalfiles As Integer = d.GetFiles.Length If totalfolders = 0 And totalfiles = 0 Then Exit Sub If cancelled Then Exit Sub GetFiles(d) End Sub Function GetFilesSize(ByRef d As DirectoryInfo) As Single Application.DoEvents() If cancelled Then Return 0 End If 'Folder Path Dim lbl1 As New Label lbl1.Text = d.FullName lbl1.Top = curtop curtop += 20 lbl1.Height = 20 'l1.Left = 100 lbl1.BackColor = Color.Black lbl1.ForeColor = Color.White Panel1.Controls.Add(lbl1) Dim totalsize As Single Dim totalfiles As Integer = d.GetFiles.Length 'Dim i As Integer 'File Info For Each f1 As FileInfo In d.GetFiles totalsize += (f1.Length) Next

For Each f1 As FileInfo In d.GetFiles If cancelled Then Exit Function Application.DoEvents() l1.Width += 1 L2.Width += 1 L3.Width += 1 L4.Width += 1 If L1.Width = 100 Then L1.Width = 0 If L2.Width = 100 Then L2.Width = 0 If L3.Width = 100 Then L3.Width = 0 If L4.Width = 100 Then L4.Width = 0 Dim l As New Label l.Text = f1.Name '& Math.Round(totalsize, 0) l.Top = curtop curtop += 14 l.Width = (f1.Length / totalsize) * Panel1.Width 'If f1.Length / 1024 <= 0 Then ' l.Width = f1.Length 'Else ' l.Width = (f1.Length / 1024) 'End If l.Height = 14 ' l.Left = 100 'i = i + 1 'If i Mod 2 = 0 Then l.BackColor = Color.BlueViolet l.ForeColor = Color.White 'Else 'l.BackColor = Color.CadetBlue 'End If Panel1.Controls.Add(l) Dim lbl2 As New Label lbl2.Text = Math.Round((f1.Length / totalsize) * 100, 2) & "%" lbl2.Left = l.Left + l.Width lbl2.AutoSize = True lbl2.Top = l.Top lbl2.Height = l.Height Panel1.Controls.Add(lbl2) Panel1.Refresh() Next For Each f1 As DirectoryInfo In d.GetDirectories totalsize += GetFilesSize(f1) 'totalsize += (f1.Length / 1024) Next

Return totalsize End Function Function GetFiles(ByRef d As DirectoryInfo) As Integer Application.DoEvents() If cancelled Then Return 0 End If 'Folder Path ' Console.WriteLine(d.FullName) Try For Each f1 As FileInfo In d.GetFiles Try If cancelled Then Exit Function Application.DoEvents() ' Console.WriteLine(f1.Name) If fn.Contains("K" & f1.Name) Then ' Dim ff As FileData ' ff = Nothing AddIfFound(f1.Name, f1.Length, f1.FullName) 'If Not ff Is Nothing Then 'End If Else Dim fd As New FileData(f1.Name, f1.Length, 1) fd.FilePath.Add(f1.FullName) 'a.Add(New FileData(f1.Name, f1.Length, 1)) ' Console.WriteLine(f1.Name) fn.Add("K" & f1.Name, fd) End If Catch ex As Exception End Try ' Dim ff As New FileData(f1.Name, f1.Length) Next Catch ex As Exception End Try Try For Each f1 As DirectoryInfo In d.GetDirectories GetFiles(f1) Next Catch ex As Exception

End Try End Function Sub AddIfFound(ByRef s As String, ByRef l As Integer, ByRef fp As String) 'As FileData Dim de As DictionaryEntry For Each de In fn If CType(de.Value, FileData).FileName = s And CType(de.Value, FileData).FileSize = l Then ' MsgBox(s1.FileName) 'fn.Item("K" & s) += 1 Dim fd As FileData = fn.Item("K" & s) fd.FileCount += 1 fd.FilePath.Add(fp) fn.Item("K" & s) = fd Console.WriteLine(fp) ' TextBox1.Text &= fp & vbCrLf ' s1.FileCount += 1 Exit Sub 'Return s1 End If Next 'Return Nothing End Sub Private Sub TreeView1_BeforeExpand(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewCancelEventArgs) Handles TreeView1.BeforeExpand Panel1.Controls.Clear() Dim d As New DirectoryInfo(e.Node.FullPath) e.Node.Nodes.Clear() For Each f As DirectoryInfo In d.GetDirectories Dim n As New TreeNode(f.Name) If f.GetDirectories.Length > 0 Then n.Nodes.Add("*") End If e.Node.Nodes.Add(n) Next started = True End Sub Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect cancelled = False Application.DoEvents() If started = True Then curtop = 0 GetFolders(e.Node.FullPath) End If End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click cancelled = True End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 'Repeated Files Logic Me.Cursor = Cursors.WaitCursor For Each d1 As String In Environment.GetLogicalDrives If d1.StartsWith("D") Then Application.DoEvents() GetFolders(d1) End If Next Panel1.Refresh() Dim de As DictionaryEntry ListBox1.BeginUpdate() For Each de In fn If cancelled Then Exit For If CType(de.Value, FileData).FileCount > 1 Then Console.WriteLine(CType(de.Value, FileData).FileCount) TextBox1.Text &= CType(de.Value, FileData).FileName & CType(de.Value, FileData).FileSize & vbCrLf Console.WriteLine(CType(de.Value, FileData).FileName & CType(de.Value, FileData).FileSize) For Each fp As String In CType(de.Value, FileData).FilePath Application.DoEvents() Console.WriteLine(fp) TextBox1.Text &= fp & vbCrLf TextBox1.Refresh() Next End If Next ListBox1.EndUpdate() Me.Cursor = Cursors.Default Exit Sub End Sub End Class ______________________________________________ frmRecycle Public Class frmRecycle Dim sh As New Shell32.Shell Dim fl As Shell32.Folder Dim fldritems As Shell32.FolderItems Dim fldritem As Shell32.FolderItem

Private Sub frmRecycle_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Const RECYCLE_BIN = &HA& Dim totalsize As Single 'Dim objShell As Object 'objShell = CreateObject("Shell.Application") fl = sh.NameSpace(RECYCLE_BIN) If fl.Items.Count > 0 Then fldritems = fl.Items() For Each fldritem In fldritems totalsize = totalsize + fldritem.Size Console.WriteLine(fldritem.Size) Next MsgBox(fldritem.Size) End If End Sub Sub a() End Sub End Class ____________________________________________-

frmMainform Public Class frmMainform Private Sub ByExtensionToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ByExtensionToolStripMenuItem.Click Dim ext As String = InputBox("Enter the File Extension") Dim f As New frmSetup If Not ext.StartsWith("*") Then f.extension = "*." & ext Else f.extension = ext End If f.ShowDialog() End Sub Private Sub ShowDriveInfoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ShowDriveInfoToolStripMenuItem.Click Dim f As New frmDrive f.ShowDialog() End Sub

Private Sub SetupFilesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SetupFilesToolStripMenuItem.Click Dim f As New frmSetup f.extension = "*.exe" f.ShowDialog() End Sub Private Sub TempFilesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TempFilesToolStripMenuItem.Click Dim f As New frmTemp f.Extension = "*.tmp" f.Label1.Text = "Total Temp Files" f.ShowDialog() End Sub Private Sub WordFilesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles WordFilesToolStripMenuItem.Click Dim f As New frmSetup f.Text = "Word Files" f.Label1.Text = "Total Word Files" ' frmSetup.Text = "Word Files" f.extension = "*.doc" f.ShowDialog() End Sub Private Sub PDFFilesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PDFFilesToolStripMenuItem.Click Dim f As New frmSetup f.Text = "PDF Files" f.Label1.Text = "Total PDF Files" f.extension = "*.pdf" f.ShowDialog() End Sub Private Sub PowerpointFilesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PowerpointFilesToolStripMenuItem.Click Dim f As New frmSetup f.Text = "PowerPoint Files" f.Label1.Text = "Total PowerPoint Files" f.extension = "*.ppt" f.ShowDialog() End Sub Private Sub ExcelFilesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExcelFilesToolStripMenuItem.Click Dim f As New frmSetup f.Text = "Excel Files" f.Label1.Text = "Total Excel Files" f.extension = "*.xls" f.ShowDialog()

End Sub Private Sub AccessFilesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AccessFilesToolStripMenuItem.Click Dim f As New frmSetup f.Text = "Access Files" f.Label1.Text = "Total Access Files" f.extension = "*.mdb" f.ShowDialog() End Sub Private Sub ZeroByteFilesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ZeroByteFilesToolStripMenuItem.Click Dim f As New frmZeroBytes f.Label1.Text = "Total Zero Bytes Files" f.extension = "*.*" f.ShowDialog() End Sub Private Sub FindRepeatedFilesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FindRepeatedFilesToolStripMenuItem.Click Dim f As New frmRepeatedFiles f.ShowDialog() End Sub Private Sub ShowDrivesFoldersInfoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ShowDrivesFoldersInfoToolStripMenuItem.Click Dim f As New Form2 f.ShowDialog() End Sub Private Sub ExitToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem1.Click End End Sub Private Sub AboutDiskAnalyzerToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutDiskAnalyzerToolStripMenuItem.Click MsgBox("DISK ANALYZERSS Version 2.0", MsgBoxStyle.Information) End Sub End Class _____________________________________________________ frmDrive Imports System.IO Public Class frmDrive Dim d As DirectoryInfo

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim x As Integer = 100 Dim drivecount As Short = Environment.GetLogicalDrives.Length Dim sp(drivecount - 1, 1) As Single Dim usedsp(drivecount - 1) As Single Dim FREEsp(drivecount - 1) As Single Dim driveletter(drivecount - 1) As String Dim i As Short Dim totalspace As Single Dim totalFREEspace As Single For Each f As String In Environment.GetLogicalDrives Dim l As New Label l.Text = f l.Top = x l.Left = 10 driveletter(i) = f G.Controls.Add(l) Dim l2 As New Label d = New DirectoryInfo(l.Text) Dim d1 As New DriveInfo(f) If d1.IsReady Then Dim siz As Single = Math.Round(d1.TotalSize / (1024 * 1024 * 1024), 2) l2.Text = siz l2.Width = siz * 20 l2.Top = x l2.BackColor = Color.Red l2.Left = l.Left + l.Width usedsp(i) = siz totalspace += siz x += 30 G.Controls.Add(l2) Dim l3 As New Label siz = Math.Round(d1.AvailableFreeSpace / (1024 * 1024 * 1024), 2) l3.Text = siz l3.Width = siz * 20 FREEsp(i) = siz totalFREEspace += siz l3.Top = x l3.BackColor = Color.GreenYellow l3.Left = l.Left + l.Width x += 30 G.Controls.Add(l3) Dim l4 As New Label l4.AutoSize = True l4.Text = d1.DriveType.ToString & ":" & d1.VolumeLabel

l4.Top = x 'l4.BackColor = Color.LightCyan l4.Left = l.Left + l.Width x += 30 G.Controls.Add(l4) sp(i, 0) = Val(l2.Text) sp(i, 1) = Val(l3.Text) i=i+1 End If Next C.ChartData = sp C.Column = 1 C.ColumnLabel = "Total" C.Column = 2 C.ColumnLabel = "Free" For j As Short = 1 To i C.Row = j C.RowLabel = driveletter(j - 1) Next C2.ChartData = usedsp C2.Row = 1 C2.RowLabel = "Used Space" For j As Short = 1 To i usedsp(j - 1) = (usedsp(j - 1) / totalspace) * 100 C2.Column = j C2.ColumnLabel = Mid(driveletter(j - 1), 1, 1) & ":" & Math.Round(usedsp(j 1)) & "%" Next C3.ChartData = FREEsp C3.Row = 1 C3.RowLabel = "Free Space" For j As Short = 1 To i FREEsp(j - 1) = (FREEsp(j - 1) / totalFREEspace) * 100 C3.Column = j C3.ColumnLabel = Mid(driveletter(j - 1), 1, 1) & ":" & Math.Round(FREEsp(j 1)) & "%" Next End Sub Private Sub C_ChartSelected(ByVal sender As System.Object, ByVal e As AxMSChart20Lib._DMSChartEvents_ChartSelectedEvent) Handles C.ChartSelected C.ShowPropertyPages() C.Refresh()

End Sub Private Sub C2_ChartSelected(ByVal sender As System.Object, ByVal e As AxMSChart20Lib._DMSChartEvents_ChartSelectedEvent) Handles C2.ChartSelected C2.ShowPropertyPages() C2.Refresh() End Sub Private Sub C3_ChartSelected(ByVal sender As System.Object, ByVal e As AxMSChart20Lib._DMSChartEvents_ChartSelectedEvent) Handles C3.ChartSelected C3.ShowPropertyPages() C3.Refresh() End Sub Private Sub G_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles G.Enter End Sub End Class

Form2 Imports System.IO Public Class Form2 Dim d As DirectoryInfo Dim f As FileInfo Dim curtop As Integer Dim started As Boolean Dim cancelled As Boolean Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim DRIVELETTER As String DRIVELETTER = InputBox("Enter the first letter of the Drive [Ex. C/D/E/F") Dim d As New DriveInfo(DRIVELETTER) If d.IsReady Then For Each d1 As String In Environment.GetLogicalDrives If d1.StartsWith(DRIVELETTER) Then Dim n As New TreeNode(d1) n.Nodes.Add("*") TreeView1.Nodes.Add(n) End If Next Else MsgBox("Invalid Drive Or Drive is Not Ready...", MsgBoxStyle.Critical)

Me.Close() End If End Sub Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect cancelled = False Application.DoEvents() If started = True Then curtop = 0 GetFolders(e.Node.FullPath) End If End Sub Sub GetFolders(ByRef d1 As String) Try ListView1.Items.Clear() Dim d As New DirectoryInfo(d1) Dim totalfolders As Integer = d.GetDirectories.Length Dim totalfiles As Integer = d.GetFiles.Length If totalfolders = 0 And totalfiles = 0 Then Exit Sub Dim totalsize As Single totalsize = GetFilesSize(d) Catch ex As Exception End Try Exit Sub End Sub Function GetFilesSize(ByRef d As DirectoryInfo) As Single Try Application.DoEvents() If cancelled Then Return 0 End If 'Folder Path 'Dim l1 As New ListViewItem 'l1.Text = d.FullName 'l1.BackColor = Color.Blue 'l1.ForeColor = Color.White 'ListView1.Items.Add(l1) Dim totalsize As Single

'File Info For Each f1 As FileInfo In d.GetFiles If f1.FullName.Length < 255 Then totalsize += (f1.Length / 1024) Dim s As New ListViewItem() Dim l2 As New ListViewItem() l2.Text = f1.Name s.Text = l2.Text 'Dim l As New ListViewItem 's.Text = Mid(f1.FullName, 1, 2) '& Math.Round(totalsize, 0) s.BackColor = Color.White s.ForeColor = Color.Black Dim l As New ListViewItem.ListViewSubItem l.Text = Mid(f1.DirectoryName, 4) s.SubItems.Add(l) s.SubItems.Add(Mid(f1.FullName, 1, 2)) ListView1.Items.Add(s) End If Next For Each f1 As DirectoryInfo In d.GetDirectories totalsize += GetFilesSize(f1) Next Return totalsize Catch ex As Exception End Try End Function Private Sub TreeView1_BeforeExpand(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewCancelEventArgs) Handles TreeView1.BeforeExpand Dim d As New DirectoryInfo(e.Node.FullPath) e.Node.Nodes.Clear() For Each f As DirectoryInfo In d.GetDirectories Dim n As New TreeNode(f.Name) If f.GetDirectories.Length > 0 Then n.Nodes.Add("*") End If e.Node.Nodes.Add(n) Next started = True End Sub Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged

Try Dim s As String For j As Integer = 0 To ListView1.Items.Count - 1 s = ListView1.SelectedItems(j).Text RichTextBox1.Text = s Next Catch ex As Exception End Try 'RichTextBox1.Text = ListView1.SelectedItems. End Sub End Class

You might also like