OPTENIR DANS UNE STRING LA TAILLE D'UN FICHIER EN KO, MO, GO...

Contenu du snippet

Private Type LARGE_INTEGER
  lowpart As Long
  highpart As Long
End Type

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Declare Function StrFormatByteSize64 Lib "shlwapi" Alias "StrFormatByteSizeW" (ByVal dw As Currency, ByVal pszBuf As Long, cchBuf As Long) As Long

' Attention : Un Currency est codé sur 8 octets mais à 4 chiffres après la virgule.
'             Il faut donc diviser par 10000 pour avoir la bonne valeur.
'             StrFormatByteSize64__C(654) retournera 6,23 MB (FAUX)
'             StrFormatByteSize64__C(654 / 10000) retournera 654 bytes
Private Function StrFormatByteSize64__C(dw As Currency) As String
  Dim StrSize As String
  StrSize = VBA.String$(64&, Chr$(0))
  Call StrFormatByteSize64(dw, StrPtr(StrSize), 64&)
  StrFormatByteSize64__C = VBA.Left$(StrSize, InStr(StrSize, Chr$(0)) - 1)
End Function

Private Function StrFormatByteSize64__LI(dw As LARGE_INTEGER) As String
  Dim dw__C As Currency
  Call CopyMemory(dw__C, dw, LenB(dw))
  StrFormatByteSize64__LI = StrFormatByteSize64__C(dw__C)
End Function

Private Function StrFormatByteSize64__LL(ByVal nFileSizeLow As Long, Optional ByVal nFileSizeHigh As Long = 0) As String
  Dim dw As LARGE_INTEGER
  dw.lowpart = nFileSizeLow
  dw.highpart = nFileSizeHigh
  StrFormatByteSize64__LL = StrFormatByteSize64__LI(dw)
End Function


Compatibilité : VB6, VBA

Disponible dans d'autres langages :

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.