Windows: Retry directory delete
Removing directories can sometimes fail on Windows if some other process has a handle to the directory.
This can cause some hard to debug errors in eg. ExternalProject as seen in issue #16569
This patch uses the same hack as is being used for moving files on Windows where RemoveDirectory is being retried with a delay a few times before finally giving up.
This shouldn't change existing behavior, but does fix the issue for us (the same issue as #16569).
This definitely ugly, but I fail to see a much better solution and a similar hack is already in the code, so I cannot see that this should make it any worse.