Home General VB.NET Get file size including Symbol
20 | 05 | 2012
This site has been updated and renewed. You have followed an old link.

Click here to go to the new site

http://www.visiblevisual.com/jupgrade

Get file size including Symbol PDF Print E-mail
User Rating: / 2
PoorBest 
Tutorials

 Code below displays a size of a specific file. The GetFileSize function will return the size including the appropriate unit formatted by the FormatSize function. 


    1 Imports System.IO

    2 

    3 Private Function GetFileSize(ByVal FilePath As String) As Long

    4 

    5     '***************************************

    6     '***** Code from visiblevisual.com *****

    7     '***************************************

    8 

    9     Dim chkFile As New FileInfo(FilePath)

   10     Dim FileSize As Long = chkFile.Length

   11     Return FormatSize(FileSize)

   12 End Function

   13 

   14 Function FormatSize(ByVal fileSize As Double) As String

   15 

   16     If fileSize < 1024 Then

   17         Return String.Format("{0:N0} B", fileSize)

   18     ElseIf (fileSize < 1024 * 1024) Then

   19         Return String.Format("{0:N2} KB", fileSize / 1024)

   20     ElseIf (fileSize < 1024 * 1024 * 1024) Then

   21         Return String.Format("{0:N2} MB", fileSize / (1024 ^ 2))

   22     ElseIf (fileSize < 1099511627776) Then

   23         Return String.Format("{0:N2} GB", fileSize / (1024 ^ 3))

   24     Else

   25         Return String.Format("{0:N2} TB", fileSize / (1024 ^ 4))

   26     End If

   27 

   28 End Function

 

Add comment


Security code
Refresh

This site has been updated and renewed. You have followed an old link.

Click here to go to the new site

http://www.visiblevisual.com/jupgrade