DirGetSize

From AutoIt Wiki

Jump to: navigation, search

Returns the size in bytes of a given directory. Adapted from AutoIt docs.

Contents

[edit] Syntax

$x = DirGetSize("path" [,flag])

[edit] Parameters

pathThe directory path to calculate. Trailing backslashes are not required. e.g. "C:\Windows".
flagDetermines the behavior and result of the function.

[edit] Flag

0   Recursive mode ON (default)
1   Extended mode ON
2   Recursive mode OFF

The flags may be combined in a logically cohesive order.

[edit] Return Value

Success: Returns size of directory. Failure: Returns -1 and sets @error to 1 if the path does not exist.

Extended mode returns an array of three elements containing the following information:

[0] = size
[1] = file count
[2] = dir count

[edit] Example

$size = DirGetSize(@HomeDrive)
Msgbox(0,"","Size(MegaBytes):" & Round($size / 1024 / 1024))

$size = DirGetSize(@WindowsDir, 2)
Msgbox(0,"","Size(MegaBytes):" & Round($size / 1024 / 1024))

$timer  = TimerInit()
$size   = DirGetSize("\\10.0.0.1\h$",1)
$diff   = Round(TimerDiff($timer) / 1000)   ; time in seconds
If IsArray($size) Then
    Msgbox(0,"DirGetSize-Info","Size(Bytes):" & $size[0] & @LF _
        & "Files:" & $size[1] & @LF & "Dirs:" & $size[2] & @LF _
        & "TimeDiff(Sec):" & $diff)
EndIf

[edit] Related Functions

DirCreate DirMove DirCopy DirRemove

Personal tools