change the "size" info in MB or GB

Hi. everytime i made a script that asks a size to a file, I have an answer in byte.
How can I have it in MB or GB?

set this_info to info for added_items
	set current_size to size of this_info
return current_size

I have tried to change it with…

set this_info to info for added_items
set current_size to size of this_info
set current_size to (current_size / 100)
return current_size

But it give strange results.

Tnx in advance

Model: iMac
AppleScript: 2.3
Browser: Camino 2.0 b4
Operating System: Mac OS X (10.6)

Hi there

I may be missing something here but I think one of the reasons you are getting strange results is because you are dividing by 100?

To convert bytes to Mb you divide by 1024 and then divide that by 1024 again to get Gb.

Hope that helps.

Again. Sorry if I have missed something here.

D :slight_smile:

Yeah, it can be right. But the result is very strange, I’m sure that the number 100 or 1024 is not the point.
And, for Snow Leopard, the right number can be 1000 not 1024, right?


set theSize to "23483284"
set textString1 to my formatSize(theSize, "MB")
set textString2 to my formatSize(theSize, "GB")
on formatSize(value, mode)
		if mode = "MB" then
			set value to value / (1024 ^ 2)
		else if mode = "GB" then
			set value to value / (1024 ^ 3)
		end if
		if value > 1000.0 then
			return ((round value) as text) & space & mode
		else
			return (((round (value * 100)) / 100) as text) & space & mode
		end if
	end formatSize
textString1 & space & textString2

I’d like to know the answer to this one too, as I’d heard of Snow Leopard’s “rounding” of the 1024 value. I was wondering if it’s just GUI or does it affect AppleScript and behind-the-scenes too.

I sure hope it’s just GUI…I’d hate to think Operating System companies had to cave-into marketers…and this coming from someone in marketing. :stuck_out_tongue:

I’d like to know the answer to this one too, as I’d heard of Snow Leopard’s “rounding” of the 1024 value. I was wondering if it’s just GUI or does it affect AppleScript and behind-the-scenes too.

I sure hope it’s just GUI…I’d hate to think Operating System companies had to cave-into marketers…and this coming from someone in marketing. :stuck_out_tongue: