Page 1 of 1

SC - Calculate Folder Size

Posted: 16 Nov 2013 12:53
by Enternal
Are there any ways to explicitly calculate folder sizes using script commands? FileSize() and Report({Size}, $Item) does not work even if I pre-calculate the folder sizes using the Calculate Folder Sizes toolbar item.

Re: SC - Calculate Folder Size

Posted: 16 Nov 2013 13:01
by highend

Code: Select all

$folders = folderreport("items:{dir {fullname}?{size raw}|{fullname}?{size raw}|}", "r");
and a loop over them (gettoken + size adding) works perfectly fine in one of my scripts...

Re: SC - Calculate Folder Size

Posted: 16 Nov 2013 17:14
by TheQwerty
If you wanted to bypass the loop you could turn the result of FolderReport into a summation expression and then use eval, and it would look something like this:

Code: Select all

$size = eval(folderreport('items:{dir {size raw}|{size raw}|0}+', 'r') . '0');
I cannot test it but I think you might be able to just replace the {dir...} template with {size raw}, I don't recall what XY returns when you request that for a drive. And really you'd probably want to do some error checking so that you don't call this when browsing "Computer", anyhow.

Re: SC - Calculate Folder Size

Posted: 16 Nov 2013 22:45
by Enternal
Ah thank you very much!

Just out of curiosity, normally you would expect that Report() should at least force reading of folder size but it doesn't. Or Report() is strictly for file sizes only? I can understand FileSize() since the name is FILE so I don't really expect too much of it to read foldersizes but Report() on the other hand...

Re: SC - Calculate Folder Size

Posted: 18 Nov 2013 14:19
by TheQwerty
Enternal wrote:Just out of curiosity, normally you would expect that Report() should at least force reading of folder size but it doesn't. Or Report() is strictly for file sizes only?
The easiest way to think of report() is that it will generate a report from the information "present" in the list - where "present" doesn't necessarily mean visible but rather readily available.

Thus, if you calculate folder sizes before calling report() it can give you that information as well.


Granted, as with most scripting commands it has been built on and modified over the years, so today it can access more information, such as extended properties, than even that description conveys.