recalculation delay in "size of folder"

has anyone dealt with this. i couldn’t find anything via a search…

When getting the size of a folder, the finder takes a few seconds to calculate, but the result is returned regardless.

choose folder myFolder
get size of folder myFolder

yelds. missing value the first time, and if reexecuted, the proper value.

as a workaround, I did:

repeat -- we should add escape clause
		set folderSize to size of folder theFolder
		if folderSize is not equal to missing value then exit repeat
end repeat

but now I have a different problem, In the interim I have code that may or may not delete files from that folder. A “get size of folder” immediately after that sometimes does not reflect the changes until it finishes recalculating, so I can’t trust it to represent the size of the folder after deletion of files.

Is there a way for me to have it pause until it accurately recalculates the folder size, as it seems to be returning whatever you would see in the get info window, which sometimes takes a while to update, especially for a large nested tree of files.

thanks,

n.

Try adding the Finder’s update command before each critical operation. It might or might not help. :?

update folder theFolder

– Rob

Thanks, but it didn’t work.

While it’s recalculating, I get a return value of 0, which is a valid possibility, so I couldn’t trust it as a flag. Nor could I trust a time-out, because large folders could take a while.

any other suggestions ? I t sounds like a bug to me in applescript.

n.

I don’t think it’s the fault of AppleScript but of the Finder. Maybe ‘info for’ (Standard Additions) will be quicker/more reliable. This does not need to be (and probably shouldn’t be) within a Finder tell block.

size of (info for alias "path:to:folder:")

– Rob

This will give the size of any folder. It should be pretty fast as well.

set the_script to “du -ks /path/to/your/folder | awk ‘{print $1}’”
set the_size to do shell script the_script
display dialog "The folder is " & the_size & “KB in size”

this script was automatically tagged for
color coded syntax by Script to Markup Code
written by Jonathan Nathan

At this point, the size can be manipulated to suit your needs.

HTH

I’ve seen this issue on another bbs (don’t remember which one, it was long ago), but it is an issue with the Finder.

–NOTE TO Tugboat – if you put the code for scripts using Jonathan Nathan’s “Script to Markup Code” in quote tags, it will save the format better.

Thanks greggo, will do

size of (info for alias “path:to:folder:”)

that worked. for some reason that standard addition waits for a folder recalc before giving a result. I’ll try the shell command method too.

thanks everyone for your help.

n.