SC - Calculate Folder Size
-
Enternal
- Posts: 1175
- Joined: 10 Jan 2012 18:26
SC - Calculate Folder Size
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
Code: Select all
$folders = folderreport("items:{dir {fullname}?{size raw}|{fullname}?{size raw}|}", "r");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
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: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.
Code: Select all
$size = eval(folderreport('items:{dir {size raw}|{size raw}|0}+', 'r') . '0');-
Enternal
- Posts: 1175
- Joined: 10 Jan 2012 18:26
Re: SC - Calculate Folder Size
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...
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
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.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?
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.
XYplorer Beta Club