Function Reference


DirGetSize

Returns the size in bytes of a given directory.

DirGetSize ( "path" [, flag = 0] )

Parameters

path The directory path to get the size from, e.g. "C:\Windows".
flag [optional] this flag determines the behaviour and result of the function, and can be a combination of the following:
    $DIR_DEFAULT (0) = (default)
    $DIR_EXTENDED (1) = Extended mode is On -> returns an array that contains extended information (see Remarks).
    $DIR_NORECURSE (2) = Don't get the size of files in subdirectories (recursive mode is Off)

Constants are defined in "AutoItConstants.au3".

Return Value

Success: the sizes that are greater than or equal to zero
Failure: -1 and sets the @error flag to non-zero if the path doesn't exist.

Remarks

If the script is paused then this function is paused too and will only continue when the script continues!

If you use the extended mode then the array returned from this function is a single dimension array containing the following elements:
$aArray[0] = Size
$aArray[1] = Files count
$aArray[2] = Dirs Count

Example

#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
        Local $iSize = DirGetSize(@HomeDrive)
        MsgBox($MB_SYSTEMMODAL, "", "Size(MegaBytes): " & Round($iSize / 1024 / 1024))

        $iSize = DirGetSize(@WindowsDir, $DIR_NORECURSE)
        MsgBox($MB_SYSTEMMODAL, "", "Size(MegaBytes): " & Round($iSize / 1024 / 1024))

        Local $hTimer = TimerInit()

        Local $aSize = DirGetSize("\\10.0.0.1\h$", $DIR_EXTENDED) ; extended mode
        If Not @error Then
                Local $iDiff = Round(TimerDiff($hTimer) / 1000) ; time in seconds
                MsgBox($MB_SYSTEMMODAL, "", "Size(Bytes): " & $aSize[0] & @CRLF _
                                 & "Files: " & $aSize[1] & @CRLF & "Dirs: " & $aSize[2] & @CRLF _
                                 & "TimeDiff(Sec): " & $iDiff)
        EndIf
EndFunc   ;==>Example