How do I avoid Error 32 while renaming a folder with Python - os.rename()
<p>I use a python script that contains the function: </p>

<pre><code>def listdirs(folder):
        return [d for d in os.listdir(folder) if os.path.isdir(os.path.join(folder, d))]
</code></pre>

<p>The function is called repeatedly to build a set of paths that are used in an operation that appends multiple copies of a dataset from individual GPS units into a single database.</p>

<p>I want to be able to append some characters to the name of the folders whose data has been appended so that those folders can be omitted from the operation the next time the larger script is run.  My hope is that this will prevent me from having to load a bunch of redundant data into the database and then just delete it since it's not useful.</p>

<p>My problem is that when I attempt to call os.rename() and use it to 'tag' the folders involved the code fails and I get:</p>

<blockquote>
  <p>WindowsError: [Error 32] The process cannot access the file because it is being used by another process</p>
</blockquote>

<p>It is not my intention for the folder to be seen as 'in use' at this point - What do I need to do to get the folders to a state where I can rename them?</p>
