• Offizieller Beitrag

    Ich brauchte gerade eine Funktion zum anzeigen von Datei-/Ordnergrößen. Die Funktion sollte automatisch (je nach Größe) die jeweils passende Einheit (Byte, KByte, MByte, GByte) ausrechnen und entsprechend zurückgeben.
    Vielleicht kann ja noch jemand so eine Funktion gebrauchen:

    Spoiler anzeigen
    [autoit]


    #include <String.au3>
    MsgBox(0, 'Beispiel 1', _ByteAutoSize(54225976, 2, 4, False))

    [/autoit] [autoit][/autoit] [autoit]

    MsgBox(0, 'Beispiel 2', _ByteAutoSize(DriveSpaceTotal('c:') * 2 ^ 20)) ; DriveSpaceTotal gibt den Wert in MByte zurück, deshalb "* 2 ^ 20"

    [/autoit] [autoit][/autoit] [autoit]

    ;===============================================================================
    ; Function Name: _ByteAutoSize($iSize, $iRound = 2, $iFormat = 0, $bThousands = True)
    ; Description:: Gibt einen Bytewert in einer bestimmten Einheit zurück
    ; Parameter(s): $iSize = Größe in Byte übergeben
    ; $iRound = Anzahl der Nachkommastellen (0...8)
    ; $iFormat = bestimmt den Rückgabewert
    ; 0 = Automatisch (je nach übergebenen Wert)
    ; 1 = in Byte
    ; 2 = in KByte
    ; 3 = in MByte
    ; 4 = in GByte
    ; $bThousands = Rückgabe mit Tausendertrennzeichen (True/False)
    ; Requirement(s): #include <String.au3>
    ; Author(s): Oscar (http://www.autoit.de)
    ;===============================================================================
    Func _ByteAutoSize($iSize, $iRound = 2, $iFormat = 0, $bThousands = True)
    Local $aSize[4] = [' Byte', ' KByte', ' MByte', ' GByte'], $sReturn
    If $iFormat < 0 Or $iFormat > 4 Then $iFormat = 0
    If $iRound < 0 Or $iRound > 8 Then $iRound = 2
    If Not IsBool($bThousands) Then $bThousands = False
    $iSize = Abs($iSize)
    If $iFormat = 0 Then
    For $i = 30 To 0 Step -10
    If $iSize > (2 ^ $i) Then
    $iFormat = $i / 10 + 1
    ExitLoop
    EndIf
    Next
    EndIf
    $sReturn = Round($iSize / (2 ^ (($iFormat - 1) * 10)), $iRound)
    If $bThousands Then $sReturn = _StringAddThousandsSep($sReturn, '.', ',')
    Return $sReturn & $aSize[$iFormat - 1]
    EndFunc ;==>_ByteAutoSize

    [/autoit]
    • Offizieller Beitrag

    Hab ich mal archiviert, wie alles von dir :D . Kann ich bestimmt mal brauchen . 8)