Hi Robert,
I'm not sure what the end goal is here - is it to loop through folders stored locally on disk (in a format similar to how the Download Attachments script downloads attachments) and add attachments to associated features hosted in ArcGIS Online if they don't already exist?
It's hard to debug the above code by just seeing a snippet. From reading through the code, lines 48 and 49 don't appear necessary - I'm not sure what if statement the else statement relates to.
What error message are you getting back? Python can also be very picky when it comes to syntax so I would suggest you keep your comments in line (e.g. lines 40 and 42).
By the sounds of it, what you need to do is get a list of all attachments associated with a particular feature (you appear to be doing this in line 27). However after that you are not looping through the file names in this, only comparing with the first file name returned. Something like this may do it:
if attachmentName not in attachmentsList:
It's been a while since you posted this so perhaps you made some ground in the meantime?
Michael