How to avoid "WindowsError: [Error 5] Access is denied"
<p>There's the script to re-create folder:</p>

<pre><code># Remove folder (if exists) with all files
if os.path.isdir(str(os.path.realpath('..') + "\\my_folder")):
        shutil.rmtree(os.path.realpath('..') + "\\my_folder", ignore_errors=True)
# Create new folder
os.mkdir(os.path.realpath('..') + "\\my_folder")
</code></pre>

<p>This works nearly always, but in some cases (on creation step) I get</p>

<pre><code>WindowsError: [Error 5] Access is denied: 'C:\\Path\\To\\my_folder'
</code></pre>

<p>What could cause this error and how can I avoid it?</p>