Yes this is possible, please see the documentation on Attachment Attributes (line 4 of the first example in that section) to get the total, and then you just need to keep track of the count as you loop through your Attachments.