Overwrite directory with shutil.rmtree and os.mkdir sometimes gives 'Access is denied' error
So I encountered the same issue. What I have been using is a pause after shutil.rmtree
. I think that pretty much anything that causes your computer to use a clock cycle would do.
All code:
import os
import shutil
import time
dataDir = 'C:/Data/'
if os.path.exists(TEMPDIR):
shutil.rmtree(TEMPDIR)
time.sleep(.0000000000000001)
os.makedirs(TEMPDIR)