conversion to MB does not work
I have the below code (which goes through the C: drive and gets file info data) and want to convert the length to a "respectable" number - i.e MB. The problem is that the line below does not do anything to the code. Any help would be appreciated:
Line is: strlength = strlength * (1024 / 1024)
Private Sub btnclick_Click(ByVal sen开发者_Python百科der As System.Object, ByVal e As System.EventArgs) Handles btnclick.Click
Dim strFilesinfo As System.IO.FileInfo
Dim strlength As Double = 0
Dim strname As String = ""
For Each strFiles As String In My.Computer.FileSystem.GetFiles("c:\")
strFilesinfo = My.Computer.FileSystem.GetFileInfo(strFiles)
strlength = strFilesinfo.Length
strname = strFilesinfo.Name
strlength = strlength * (1024 / 1024)
lstData.Items.Add(strname & " " & strlength)
Next
End Sub
End Class
You're dividing by 1:
strlength = strlength * (1024 / 1024)
The parenthesis makes 1024 divided by 1024 happen first which equals 1.
Should be
strlength = strlength / 1024 / 1024
精彩评论