The last document to be deleted shows up in children so the length is still 1. I changed the condition to children.length == 1, but that produced the next issue.

When it tried to delete the space I get the following error: 10:59:01,581 ERROR [org.alfresco.web.ui.common.Utils] Unable to delete Space due to system error: null. Ive ascertained that it is referring to the document being deleted.

Any thoughts of how to fix this or get around it would be much appreciated.