diff --git a/Source Code/Classes/DirectoryCleanser.vb b/Source Code/Classes/DirectoryCleanser.vb index 2c2b162..5f88da2 100644 --- a/Source Code/Classes/DirectoryCleanser.vb +++ b/Source Code/Classes/DirectoryCleanser.vb @@ -16,14 +16,14 @@ End Function Public Shared Function DirFileSize(ByVal DirPath As String, ByVal FileType As String) - Dim FileSize As Integer = 0 + Dim FileSize As Int64 = 0 For Each item As IO.FileInfo In New IO.DirectoryInfo(DirPath).GetFiles() If item.Extension = "." + FileType Or FileType = "" Then FileSize += item.Length End If Next - Return FileSize + Return FormatFileSize(FileSize) End Function Public Shared Function DirFileList(ByVal DirPath As String, ByVal FileType As String) @@ -37,4 +37,45 @@ Return FileList.ToString End Function + + '' Credit: https://stackoverflow.com/a/39449400 + Public Shared Function FormatFileSize(ByVal lngFileSize As Long) As String + + Dim x As Int64 : x = 0 + Dim Suffix As String : Suffix = "" + Dim Result As Single : Result = lngFileSize + + Do Until Int(Result) < 1000 + x = x + 1 + Result = Result / 1024 + Loop + + Result = Math.Round(Result, 2) + + Select Case x + Case 0 + Suffix = "Bytes" + Case 1 'KiloBytes + Suffix = "KB" + Case 2 'MegaBytes + Suffix = "MB" + Case 3 'GigaBytes + Suffix = "GB" + Case 4 'TeraBytes + Suffix = "TB" + Case 5 'PetaBytes + Suffix = "PB" + Case 6 'ExaBytes + Suffix = "EB" + Case 7 'ZettaBytes + Suffix = "ZB" + Case 8 'YottaBytes + Suffix = "YB" + Case Else + Suffix = "Too big to compute :)" + End Select + + FormatFileSize = Format(Result, "#,##0.00") & " " & Suffix + + End Function 'FormatFileSize End Class diff --git a/Source Code/Forms/frmFileMover.vb b/Source Code/Forms/frmFileMover.vb index 93b2e2a..27b9960 100644 --- a/Source Code/Forms/frmFileMover.vb +++ b/Source Code/Forms/frmFileMover.vb @@ -43,7 +43,7 @@ Public Class frmFileMover Try txtFolderStats.Text = "" txtFolderStats.Text = "Old Directry File Count : " + DirFileCount(txtOldDirectory.Text, txtFileType.Text).ToString + vbCrLf - txtFolderStats.Text = txtFolderStats.Text + "Old Directory File Size : " + DirFileSize(txtOldDirectory.Text, txtFileType.Text).ToString + " bytes" + vbCrLf + txtFolderStats.Text = txtFolderStats.Text + "Old Directory File Size : " + DirFileSize(txtOldDirectory.Text, txtFileType.Text).ToString + vbCrLf txtFolderStats.Text = txtFolderStats.Text + "New Directry Current File Count : " + DirFileCount(txtNewDirectory.Text, txtFileType.Text).ToString + vbCrLf txtFolderStats.Text = txtFolderStats.Text + "New Directory Current File Size : " + DirFileSize(txtNewDirectory.Text, txtFileType.Text).ToString + " bytes" Catch ex As Exception diff --git a/Source Code/Forms/frmFileRemover.vb b/Source Code/Forms/frmFileRemover.vb index a0a83a4..4b3881d 100644 --- a/Source Code/Forms/frmFileRemover.vb +++ b/Source Code/Forms/frmFileRemover.vb @@ -43,7 +43,7 @@ Public Class frmFileRemover Try txtFolderStats.Text = "" txtFolderStats.Text = txtFolderStats.Text + "Directry File Count : " + DirFileCount(txtDirectory.Text, txtFileType.Text).ToString + vbCrLf - txtFolderStats.Text = txtFolderStats.Text + "Directory File Size : " + DirFileSize(txtDirectory.Text, txtFileType.Text).ToString + " bytes" + vbCrLf + txtFolderStats.Text = txtFolderStats.Text + "Directory File Size : " + DirFileSize(txtDirectory.Text, txtFileType.Text).ToString + vbCrLf Catch ex As Exception MsgBox(ex.ToString) End Try diff --git a/Source Code/My Project/AssemblyInfo.vb b/Source Code/My Project/AssemblyInfo.vb index fb5ab8a..e318f28 100644 --- a/Source Code/My Project/AssemblyInfo.vb +++ b/Source Code/My Project/AssemblyInfo.vb @@ -12,7 +12,7 @@ Imports System.Runtime.InteropServices - + @@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices ' by using the '*' as shown below: ' - - + +