Last item of a list query...

Hi There,

Just a quick query regarding catching the last item of a list.

I have a script that processes files dropped onto it. Can anyone tell me if there’s a way to catch whether or not the last item is being processed? I was going to put in some sort of count but I just wondered if I could put in something like this:-

if theFile is the last item of someFiles then display dialog "Last One"

By the way, I’ve tried the above but no luck.

Thanks in advance.

Regards,

Nick

Hi Nick,

use an “accessible” index variable


set maxFiles to count someFiles
repeat with i from 1 to maxFiles
	set theFile to item i of someFiles
	if i is maxFiles then display dialog "Last One"
	-- do something
end repeat

Thanks for the reply Stefan.
I was just in the process of replying to my own question but I’m glad you got there first.
It gave me another way of solving the problem.

I found that changing both items to text allowed me to compare them:-

if (theFile as text) is not (the last item of someFiles as text) then set fileNameNoExt to fileNameNoExt & ", "

Thanks again for your time.

Regards,

Nick