Sign in to follow this  
Followers 0
neogia

Retrieve The Size Of A Folder And Subdirectories

7 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



Func _GetFolderSize($dir, $units = "b")
At your way, but this makes the same thing that DirGetSize, that comes in-built with Autoit.

Anyway, interesting use of object.

Share this post


Link to post
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

Share this post


Link to post
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...

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

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

i like it.

Edited by slightly_abnormal

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

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

[center]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.[/center]

Share this post


Link to post
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
Sign in to follow this  
Followers 0