Top-rated recipes tagged "move"http://code.activestate.com/recipes/tags/move/top/2012-04-30T11:09:05-07:00ActiveState Code RecipesMove files with rename if required (Python) 2012-04-30T11:09:05-07:00John Reidhttp://code.activestate.com/recipes/users/4023487/http://code.activestate.com/recipes/578116-move-files-with-rename-if-required/ <p style="color: grey"> Python recipe 578116 by <a href="/recipes/users/4023487/">John Reid</a> (<a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/move/">move</a>, <a href="/recipes/tags/rename/">rename</a>). Revision 2. </p> <p>A python script that renames (moves) files to a destination directory. However it will not overwrite existing files. The script uses a renaming strategy where a count is incremented in order to avoid naming conflicts.</p> <p>Example usage::</p> <pre class="prettyprint"><code>mv-rename a.ext b.ext target-dir/ </code></pre> <p>would mv a.ext and b.ext into the target directory. If::</p> <pre class="prettyprint"><code>target-dir/a.ext target-dir/b.ext </code></pre> <p>already exist, the newly moved files would be named::</p> <pre class="prettyprint"><code>target-dir/a-&lt;N&gt;.ext target-dir/b-&lt;M&gt;.ext </code></pre> <p>where &lt;N&gt; and &lt;M&gt; are the lowest numbers such that there is no conflict.</p>