Ihave a project setup like this
project/src/test/python/main.py
project/test-output
i want the main-testscript to delete and then recreate the test-output folder.
So i put this code there.
if os.path.exists("test-output"):
shutil.rmtree("test-output")
os.mkdir("test-output")
But when i run it with
d:\projects\thisproject>python src\test\python\main.py
I get a access denies error from windows. [Error 5]
How to fix this?
the mkdir command works fine tough.
I have recently seen this behaviour of shutil.rmtree() myself under Windows 7, also when creating and destroying test folders from unit tests. And, no, there was nothing having an active reference to the directory or anything in it, not even an explorer window. My 'solution' (if you can call it that) was to do:
shutil.rmtree("my/test/dir", ignore_errors=True)
Not exactly a thing of beauty, but it solved the problem for me.
By the way, this was a 64 bit Windows 7 machine, and on an SSD. A co-worker reported the same problem with shutil.rmtree() when deleting a directory on a Windows share on another machine. I'm getting a feeling that Windows is caching things here, if only briefly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With