Jump to content

Retrieve The Size Of A Folder And Subdirectories


neogia
 Share

Recommended Posts

MsgBox(0,"", _GetFolderSize("C:\WINDOWS", "mb"))

Func _GetFolderSize($dir, $units = "b")
    $obj = ObjCreate("Scripting.FileSystemObject")
    If @error == 0 Then
        $folder = $obj.GetFolder($dir)
        Select
        Case $units == "b"
            Return $folder.Size
        Case $units == "kb"
            Return $folder.Size/1024
        Case $units == "mb"
            Return $folder.Size/1024/1024
        Case $units == "gb"
            Return $folder.Size/1024/1024/1024
        Case $units == "tb"
            Return $folder.Size/1024/1024/1024/1024
        EndSelect
    Else
        MsgBox(0,"","An error occurred, check that " & $dir & " exists.")
    EndIf
EndFunc

Edited by neogia

[u]My UDFs[/u]Coroutine Multithreading UDF LibraryStringRegExp GuideRandom EncryptorArrayToDisplayString"The Brain, expecting disaster, fails to find the obvious solution." -- neogia

Link to comment
Share on other sites

Interesting. There was a post in Support, and a couple others were trying to find a way to do it, and I just assumed that function didn't exist in AutoIt. Just goes to show you what happens when you assume....

sometimes your wrong.

[u]My UDFs[/u]Coroutine Multithreading UDF LibraryStringRegExp GuideRandom EncryptorArrayToDisplayString"The Brain, expecting disaster, fails to find the obvious solution." -- neogia

Link to comment
Share on other sites

Interesting. There was a post in Support, and a couple others were trying to find a way to do it, and I just assumed that function didn't exist in AutoIt. Just goes to show you what happens when you assume....

sometimes your wrong.

Most of those asked in support, but mostly are responded in the read help of AutoIt. Anyway, interesting...

Link to comment
Share on other sites

  • Moderators

i think the built in one only gets the size in megabytes... but i could be wrong.

i like it.

$size = DirGetSize("C:")

Msgbox(0,"","Size(MegaBytes):" & Round($size / 1024 / 1024))

$size = DirGetSize("C:\Windows", 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

It doesn't say specifically that it returns in bytes but... the Size(MegaBytes):" & Round($size / 1024 / 1024) gives it away :think:. Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...