Urgent problem...Need Help

i think i found a bug in a script but m still not sure about it.
The thing is that i am trying to get the size of a folder after adding it to a hot folder.

the script is the following:

 on adding folder items to this_folder after receiving added_items

so then i ask to get the size of the added items.
the problem is that the first time i drop a file or folder with a new size, the return size value is missing.
After if i do the same action with the same folder info everything works normal. this is on a local machine.

And the same problems occurs if i am dropping a file from a distant computer, to the hot folder in my computer, i always get the value of the size missing. Even after repetitive tests it wont work. this is on the network.

Please help me on this one guys,
it is a matter of life and death :o!!

Are you using the Finder to get the size? It’s been a common problem ever since OS X was introduced. X’s Finder only bothers to find out the relevant information about an item on disk when it needs to. When a script asks the Finder for the ‘size’ of an item (or some other detail such as the ‘creator type’), the Finder asks System Events (I think) for the information, but stupidly doesn’t wait for the reply before returning “don’t know” to the script. The next time the script runs, the Finder has received the requested information and returns that instead.

There doesn’t seem to be any consistently reliable method in the Finder for getting a folder size first time. With small folders, or with files, simply asking twice seems to do the trick, but it doesn’t work with large folders:

-- Assuming 'this_item' is one of the aliases in 'these_items'.
tell application "Finder"
	set f_size to size of this_item
	set f_size to size of this_item
end tell

In Tiger, using System Events instead seems to be reliable. But you can’t do this in Jaguar because that version of System Events doesn’t recognise a ‘size’ property. I don’t know what the situation is with Panther.

tell application "System Events"
	set f_size to size of this_item
end tell

The best bet seems to be to use ‘info for’ from the StandardAdditions. It’s consistently reliable over all systems and it can also be used to confirm that the alias really does refer to a folder:

-- No 'tell' block.
set info_rec to (info for this_item)
if (folder of info_rec) and not (package folder of info_rec) then
	set f_size to size of info_rec
	-- The item's a file or a package.
end if


All problems on these forums are presumably urgent to the original posters, but other visitors to the site can only reply as they have the knowledge, the interest, and the time. Urging replies, or using uninformative subject lines like “Urgent problem…”, can actually reduce your chances of a response. :slight_smile: