Document purge

Hi,

I have a script to Purge the families from a folder.

but sometimes I get this error:

Can you help me understand why?

Thank you

This is the error

Erm, if the items are deleted the IDs are going to go automatically but you can’t just delete an ID.

can you explain it better please? It work in most of cases, so why sometimes no?