You are dead. the documentation does not even list ERROR_ACCESS_DENIED as a possible error code for this function, so it could be an error.
I would do as you suggest in implementing a retry / snooze strategy.
In other words, if you get this error, try again up to three times without delay (obviously, stop at any point here if you get a return code without errors), then up to four times with delays (for example, 100 milliseconds, 500 milliseconds, 1 second and 2 seconds).
This strategy (which I used before) usually bypasses any temporary lack of resources. If you still cannot create the directory after 7 attempts and 3.6 + seconds, you can probably safely assume that this will not happen.
Your function may be as ugly as (pseudo-code):
def createMyDir (dirname): if createDir (dirName) return true; if createDir (dirName) return true; if createDir (dirName) return true; sleep (100) if createDir (dirName) return true; sleep (500) if createDir (dirName) return true; sleep (1000) if createDir (dirName) return true; sleep (2000) return createDir (dirName);
but you might want you to make it a little more elegant:
def createMyDir (dirname): delay = pointer to array [0, 0, 0, 100, 500, 1000, 2000, -1] okay = createDir (dirName) while not okay and [delay] not -1: if [delay] not 0: sleep ([delay]) delay = next delay okay = createDir (dirName) return okay
source share