keep getting 0 for a folder size that isn't empty

Hello.

I’m trying to make a script that will give me a list of folders (within a parent folder) with thier sizes in GB’s.


set childFolders to {} as list
set entrySize to ""

tell application "Finder"
	activate
	set childFolders to (every folder of alias "Volume:TheParentFolder:")
	repeat with anEntry in childFolders
		set entrySize to size of anEntry
		set entrySize to (entrySize / 1024)--errors highligting 1024
		set entrySize to (entrySize / 1024)
		set entrySize to (entrySize / 1024)
		set entrySize to (round (entrySize * 100)) / 100
                display dialog entrySize
	end repeat
end tell

When I run this, the first time through the repeat everything works fiine. On the second run through I get a an applescript error that says “Can’t make missing value in real” (see code above)

Then, I thought I’d add a repeat while entrySize is “” to wait while maybe the script could get the file size. I’d heard that sometime this happens with AS and OS X.


set childFolders to {} as list
set entrySize to ""


tell application "Finder"
	activate
	set childFolders to (every folder of alias "Volume:TheParentFolder:")
	repeat with anEntry in childFolders
		repeat while entrySize is ""
		set entrySize to size of anEntry
		end repeat
		set entrySize to (entrySize / 1024)
		set entrySize to (entrySize / 1024)
		set entrySize to (entrySize / 1024)
		set entrySize to (round (entrySize * 100)) / 100
		display dialog entrySize as text
	end repeat
end tell

When I run this, the first time through the repeat display dialog works fine. But when the second and successive times through, the return is 0 for all folders.

Sorry for the long post. Any help is appreciated! :slight_smile:

Browser: Firefox 1.5
Operating System: Mac OS X (10.4)

hi rodeashe,

you have to reset the value of entrySize in the repeat loop. If not it will not be “” or ‘missing value’ for the the second folder and the size value can’t be set at all.

btw: to be correct: “” is an empty string - something different than ‘missing value’

maybe you can try:

tell application "Finder"
	activate
	set childFolders to (every folder of alias "Volume:TheParentFolder:")
	repeat with anEntry in childFolders
		set entrySize to missing value
		repeat until entrySize ≠ missing value
			set entrySize to size of anEntry
			delay 1
		end repeat
		set entrySize to (entrySize / 1024)
		set entrySize to (entrySize / 1024)
		set entrySize to (entrySize / 1024)
		set entrySize to (round (entrySize * 100)) / 100
		display dialog entrySize as text
	end repeat
end tell

Thanks, Dominik. That worked great. I actually was able to take out the delay with no problem.

Also, is this the best way to convert from bytes to GB’s while showing 2 decimal places after the ‘dot’.

Thanks, again!:slight_smile:

Hi, Jacques.

This is just great. Thanks a lot!

bret