SC - Calculate Folder Size

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
Enternal
Posts: 1175
Joined: 10 Jan 2012 18:26

SC - Calculate Folder Size

Post 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.

highend
Posts: 14954
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: SC - Calculate Folder Size

Post 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...
One of my scripts helped you out? Please donate via Paypal

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: SC - Calculate Folder Size

Post 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.

Enternal
Posts: 1175
Joined: 10 Jan 2012 18:26

Re: SC - Calculate Folder Size

Post 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...

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: SC - Calculate Folder Size

Post 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.

Post Reply