FolderSize() - get folder size quickly

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
gwarble
Posts: 524
Joined: 30 Sep 2013, 15:01

FolderSize() - get folder size quickly

13 Jul 2020, 19:13

This is the fastest method I could find to get the size of a folder, any way to do this faster or similarly fast with the WinAPI? File Loop, PowerShell, COM, winmgmts?

Code: Select all

FolderSize(folder) { ;gwarble 2020 - any faster method to get folder size?
Loop, Parse, % RunCMD("robocopy /l /nfl /ndl " folder " . /r:0 /w:0 /e /bytes"), `n, `r
 If InStr(A_LoopField,"Bytes :") ;thanks SKAN for RunCMD()
  For each, z in StrSplit(RegExReplace(A_LoopField, "\s+", " "), " ")
   If (A_Index = 4) ;probably much better ways to parse result
    Return z
}
thanks to SKAN for RunCMD() https://www.autohotkey.com/boards/viewtopic.php?f=6&t=74647
thanks to SKAN, FormatBytes() is useful in this case: https://www.autohotkey.com/boards/viewtopic.php?f=6&t=3567
Last edited by gwarble on 13 Jul 2020, 23:44, edited 1 time in total.
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: FolderSize() - get folder size quickly

13 Jul 2020, 22:03

Code: Select all

bytes := ComObjCreate("Scripting.FileSystemObject").GetFolder(folderpath).Size
User avatar
gwarble
Posts: 524
Joined: 30 Sep 2013, 15:01

Re: FolderSize() - get folder size quickly

13 Jul 2020, 23:39

thanks, exactly what i wanted (faster and not dependent on another exe)

Works on A_Desktop, any idea about overcoming error 0x800A0046 when running on A_WinDir?
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: FolderSize() - get folder size quickly

14 Jul 2020, 01:08

CTL_E_PERMISSIONDENIED
You will need adequate permissions to access that folder.
I dont want to get into changing computer settings (google if interested) but maybe someone can chime in on a simple solution or another method.
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: FolderSize() - get folder size quickly

14 Jul 2020, 17:45

Xtra wrote:
13 Jul 2020, 22:03

Code: Select all

bytes := ComObjCreate("Scripting.FileSystemObject").GetFolder(folderpath).Size
Nice!
Useful for known folders. Unable to use it at root level.
My Scripts and Functions: V1  V2
User avatar
gwarble
Posts: 524
Joined: 30 Sep 2013, 15:01

Re: FolderSize() - get folder size quickly

14 Jul 2020, 18:18

Interesting results in one scenario here, COM wins locally, robocopy wins on network share via VPN over internet:

Code: Select all

Local Folder:
Robocopy:	127 GB		5304ms
COM:		127 GB		4555ms

Network Share via VPN over internet:
Robocopy:	16.8 GB		31294ms
COM:		16.8 GB		37097ms
overall very comparable results in both cases
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .
User avatar
cyruz
Posts: 346
Joined: 30 Sep 2013, 13:31

Re: FolderSize() - get folder size quickly

18 Jul 2020, 20:24

gwarble wrote:
13 Jul 2020, 23:39
thanks, exactly what i wanted (faster and not dependent on another exe)

Works on A_Desktop, any idea about overcoming error 0x800A0046 when running on A_WinDir?

Running the script as admin alone will not do. A quick but unpractical way would be to get the SeBackupPrivilege, while running as admin:

Code: Select all

DllCall( "ntdll.dll\RtlAdjustPrivilege", UInt,17, Int,1, Int,0, Int,0 )
ABCza on the old forum.
My GitHub.

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 150 guests