SEE BOTTOM OF THIS POST FOR UPDATE ON THIS PLEASE.
I have the below code that searches through directories and displays the largest file in the directory. the problem is that it displays it in KB – how on earth do I convert it to MB? The file size comes out way too large so want easier reading – thanks for the help:
Private Sub btnGetMax_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetMax.Click
ClearList()
Dim dblSize As Integer = 0
Dim dblMax As Integer = 0
Dim strMax As String = ""
Dim objFileInfo As System.IO.FileInfo
For Each strFile As String In My.Computer.FileSystem.GetFiles("c:\temp", FileIO.SearchOption.SearchAllSubDirectories)
objFileInfo = My.Computer.FileSystem.GetFileInfo(strFile)
/*whats the size of the files?*/
dblSize = objFileInfo.Length
If dblSize > dblMax Then
dblMax = dblSize
strMax = objFileInfo.FullName
End If
Next
MessageBox.Show("Largest file in .Net folder is " & vbCrLf &
strMax & vbCrLf &
dblMax.ToString("N0"))
End Sub
SHOULD HAVE MADE MYSELF MORE CLEAR! I KNOW HOW TO CONVERT KB TO MB BUT NO IDEA HOW I INCORPORATE THAT INTO MY CODE – DO I ADD ANOTHER VARIABLE FOR STRMAX AS /1024…..EXCEPT I ALREADY HAVE STRMAX VARIABLE…..STILL VERY MUCH A BEGINNER GUYS.
I know how to convert KB to MB – the problem is how do I incorporate that into my code? Do I add another variable
(Sorry for the previous answer with 1024, a mistaken assumption)
To your question of converting from kB to MB, you can surely assume by SI standard:
Ergo, divide by 1000.
For the unconvinced, I encourage you to read this.
Since software like Microsoft Windows expresses storage quantities in multiples of 1024 bytes, change your code to:
(since you are printing dblMax & your file size is in bytes, not kB)