How would one get the size of a folder? I can’t seem to figure it out.
Thanks!
How would one get the size of a folder? I can’t seem to figure it out.
Thanks!
Here’s one way to do it. The handler is included but not necessary unless you want results that are readable by humans. ![]()
set byteSize to size of (info for alias "path:to:folder")
set size_ to convertByteSize from byteSize
to convertByteSize from byteSize -- by Nigel Garvey
if byteSize ? 1.099511627776E+12 then -- Terabytes (2 ^ 40)
((byteSize / 1.099511627776E+12 div 0.01 / 100.0) as string) & " TB"
else if byteSize ? 1.073741824E+9 then -- Gigabytes (2 ^ 30)
((byteSize / 1.073741824E+9 div 0.01 / 100.0) as string) & " GB"
else if byteSize ? 1048576 then -- Megabytes (2 ^ 20)
((byteSize / 1048576 div 0.01 / 100.0) as string) & " MB"
else if byteSize ? 1024 then -- Kilobytes (2 ^ 10)
((byteSize div 1024) as string) & " K"
else
(byteSize as string) & " bytes"
end if
end convertByteSize
– Rob
I’d have thought that you of all people would know the limits of this forum software by now, Rob ![]()
else if byteSize ? 1048576 then
huh?
![]()
Expected “then”, etc. but found unknown token.
and it highlights the “?” after "if byteSize
Dammit. :x Thanks for the heads up. ![]()
set byteSize to size of (info for alias "path:to:folder")
set size_ to convertByteSize from byteSize
to convertByteSize from byteSize -- by Nigel Garvey
if byteSize is greater than or equal to 1.099511627776E+12 then -- Terabytes (2 ^ 40)
((byteSize / 1.099511627776E+12 div 0.01 / 100.0) as string) & " TB"
else if byteSize is greater than or equal to 1.073741824E+9 then -- Gigabytes (2 ^ 30)
((byteSize / 1.073741824E+9 div 0.01 / 100.0) as string) & " GB"
else if byteSize is greater than or equal to 1048576 then -- Megabytes (2 ^ 20)
((byteSize / 1048576 div 0.01 / 100.0) as string) & " MB"
else if byteSize is greater than or equal to 1024 then -- Kilobytes (2 ^ 10)
((byteSize div 1024) as string) & " K"
else
(byteSize as string) & " bytes"
end if
end convertByteSize
– Rob
Convert Script to Markup Code will catch & correct this for you if you wanted to start using it…
Jon
Convert Script to Markup Code will catch & correct this for you if you wanted to start using it…
And a fine app it is! I’ve had it installed since it was released but, for some reason, I never reach for it. In this case, I’ve modified the clipping file that contains the code so I don’t make the same mistake again. I generally use the the verbose terminology in my scripts but that code came from NG and I never bothered to change it. Until now.
– Rob