We were looking through the detail you had sent in via the other ticket earlier, before we knew you had solved the issue. We assumed that the issue would’ve been related to potentially open file handles or something similar.
With this additional information, it seems like that assumption is almost certainly the culprit. Hopefully you don’t come across the same issue again, but if you do - wait a few minutes then try again.
You are 100% correct - this isn’t a great outcome. We can definitely look into this a bit further to work out what’s going on.
Additional to the information previously discussed, another thought crossed my mind regarding recursive deleting of larger file/folder structures on a windows environment. I have heard that Powershell can in fact fail when attempting to recursively delete files/folders on Windows systems, in short because windows runs the operations asynchronously. This may in fact show similar traits as what you are seeing.
A simple example of the issue is this:
Does folder A/B/C Exist? Yes
Send command to delete A/B/C
Does folder A/B/D Exist? Yes
Send command to delete A/B/D (This command gets caught on a busy thread)
A/B/C gets deleted
Should A/B be empty? Yes
Send command to delete A/B
Command A/B tries to delete but is in use due to the delete A/B/D command still not executing.
So the above issue and as well as other legitimately open file handles need to be addressed. One suggestion to deal with this is by finding the deepest child-path and removing the files using the -force command, then remove the folder that they were in, then again find the next deepest child path.