After upload, delete files smartly

The file may not exist or the order in `$toDelete` may come out wrong. This is bulletproof.