Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / VB

Print File Size

4.86/5 (4 votes)
18 Jul 2010CPOL 8.8K  
Here is an alternate I like to use. Private Function TranslateFileSize(ByVal size As Double) As String Try Dim filesizename() As String = { Bytes, KB, MB, GB, TB, PB, EB, ZB, YB} Dim pow As Double = Math.Floor(Math.Log(size,...
Here is an alternate I like to use.

Private Function TranslateFileSize(ByVal size As Double) As String
    Try
        Dim filesizename() As String = {" Bytes", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB"}
        Dim pow As Double = Math.Floor(Math.Log(size, 1024))
        Return String.Concat(Math.Round(size / Math.Pow(1024, pow), 2), " ", filesizename(CInt(pow)))
    Catch ex As Exception
        Return size
    End Try
End Function

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)