Advertisement
3DotDev

Afficher taille fichier/répertoire en octets

Dec 18th, 2014
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.66 KB | None | 0 0
  1. '########################################################
  2. ' Credits 3DotDev from http://3dotdevcoder.blogspot.fr/
  3. '########################################################
  4.     Public Function BytestoString(ByVal Size As Long) As String
  5.         Dim txt$ = String.Empty
  6.         Try
  7.             Dim i% = 1024
  8.             Dim i1% = i * i
  9.             Dim bl As Boolean = Size < CType(i, Long)
  10.             If bl Then
  11.                 Return Size.ToString("D") & If(Size <= 1, " octet", " octets")
  12.             Else
  13.                 Dim dbl As Double = CType(Size, Double) / CType(i, Double)
  14.                 bl = dbl < 1000
  15.                 If bl Then
  16.                     Return (CType(Size, Double) / CType(i, Double)).ToString("N") & " Ko"
  17.                 Else
  18.                     bl = dbl < 1000000
  19.                     If bl Then
  20.                         Return (CType(Size, Double) / CType(i1, Double)).ToString("N") & " Mo"
  21.                     Else
  22.                         bl = dbl < 30000000
  23.                         If bl Then
  24.                             Return ((CType(Size, Double) / CType(i1, Double)) / CType(i, Double)).ToString("N") & " Go"
  25.                         End If
  26.                     End If
  27.                 End If
  28.             End If
  29.         Catch ex As Exception
  30.             txt = Size.ToString
  31.             Return txt
  32.         End Try
  33.         Return txt
  34.     End Function
  35.  
  36. '############################# Comment l'utiliser ##############################
  37.  
  38. Dim fi As New FileInfo("C:\Users\jm\Desktop\My 8 Files Uploader.exe")
  39. MsgBox(BytestoString(fi.Length.ToString))
  40.  
  41. '##############################################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement