Removing an empty directory is not working because of xl.DeleteObject() was only checking if the passed prefix is an actual object but it should also check if it is an empty directory.