Popular Python recipes tagged "rename"http://code.activestate.com/recipes/langs/python/tags/rename/2012-07-21T02:38:33-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-<N>.ext
target-dir/b-<M>.ext
</code></pre>
<p>where <N> and <M> are the lowest numbers such that there
is no conflict.</p>
EXIF-date-based JPEG files rename using PIL (Python)
2012-07-21T02:38:33-07:00Jorge Barnabyhttp://code.activestate.com/recipes/users/4182918/http://code.activestate.com/recipes/578219-exif-date-based-jpeg-files-rename-using-pil/
<p style="color: grey">
Python
recipe 578219
by <a href="/recipes/users/4182918/">Jorge Barnaby</a>
(<a href="/recipes/tags/date/">date</a>, <a href="/recipes/tags/exif/">exif</a>, <a href="/recipes/tags/jfif/">jfif</a>, <a href="/recipes/tags/jpeg/">jpeg</a>, <a href="/recipes/tags/jpg/">jpg</a>, <a href="/recipes/tags/photo/">photo</a>, <a href="/recipes/tags/pil/">pil</a>, <a href="/recipes/tags/rename/">rename</a>).
Revision 2.
</p>
<p>Rename JPEG files according to EXIF-date using PIL [library].</p>
<p>If global variable CREATE_HARDLINK is set, script creates Windows (XP) batch file
for creating hardlink version of source files.</p>
<p>PIL available here: <a href="http://www.pythonware.com/products/pil/" rel="nofollow">http://www.pythonware.com/products/pil/</a></p>
AutoRename.py (Python)
2010-08-01T21:39:54-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/577342-autorenamepy/
<p style="color: grey">
Python
recipe 577342
by <a href="/recipes/users/2608421/">Stephen Chappell</a>
(<a href="/recipes/tags/rename/">rename</a>).
</p>
<p>A friend was trying to open files with Korean names and was finding that Windows 7 was giving him errors. There were well over 22,000 files to deal with, and he did not want to rename them all individually. As a result, this program was quickly written to help him in renaming his vast assortment of files and folders so that he could easily open them in his resource viewer application.</p>
Make unique file name (Python)
2010-04-18T21:07:52-07:00Denis Barmenkovhttp://code.activestate.com/recipes/users/57155/http://code.activestate.com/recipes/577200-make-unique-file-name/
<p style="color: grey">
Python
recipe 577200
by <a href="/recipes/users/57155/">Denis Barmenkov</a>
(<a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/name/">name</a>, <a href="/recipes/tags/rename/">rename</a>).
Revision 2.
</p>
<p>Sometimes it is important to save data in the file but the file with the specified name already exists. This function creates a file name that is similar to the original by adding a unique numeric suffix. This avoids the renaming of existing files.</p>
Rename MP3 files from ID3 tags (does not require external ID3 modules) (Python)
2011-11-05T15:27:32-07:00ccpizzahttp://code.activestate.com/recipes/users/4170754/http://code.activestate.com/recipes/576811-rename-mp3-files-from-id3-tags-does-not-require-ex/
<p style="color: grey">
Python
recipe 576811
by <a href="/recipes/users/4170754/">ccpizza</a>
(<a href="/recipes/tags/id3/">id3</a>, <a href="/recipes/tags/mp3/">mp3</a>, <a href="/recipes/tags/rename/">rename</a>).
Revision 5.
</p>
<p>Rename MP3 files in the current folder according to ID3 tags. This is based on Ned Batchelder's id3reader class. I only added the code in the <code>__main__</code> method.</p>
<ul>
<li>When run without arguments, the script renames the files in the current folder. The directory can be specified explicitly as the first argument.</li>
<li>The files do not need to necessarily have the <code>MP3</code> extension.</li>
<li>To move the files to directories based on album name use the <code>-d</code> switch.</li>
<li>Does not work with other file types, such as OGG, M4A, MP4, etc.</li>
<li>This is a quick and dirty script that works for me most of the times. If you need more power, try mutagen, picard, mp3tag or something similar.</li>
</ul>
EXIF-date-based JPEG files rename using PIL (Python)
2009-02-10T07:28:48-08:00Denis Barmenkovhttp://code.activestate.com/recipes/users/57155/http://code.activestate.com/recipes/576646-exif-date-based-jpeg-files-rename-using-pil/
<p style="color: grey">
Python
recipe 576646
by <a href="/recipes/users/57155/">Denis Barmenkov</a>
(<a href="/recipes/tags/date/">date</a>, <a href="/recipes/tags/exif/">exif</a>, <a href="/recipes/tags/jfif/">jfif</a>, <a href="/recipes/tags/jpeg/">jpeg</a>, <a href="/recipes/tags/jpg/">jpg</a>, <a href="/recipes/tags/photo/">photo</a>, <a href="/recipes/tags/pil/">pil</a>, <a href="/recipes/tags/rename/">rename</a>).
Revision 4.
</p>
<p>Rename JPEG files according to EXIF-date using PIL [library].</p>
<p>If global variable CREATE_HARDLINK is set, script creates Windows (XP) batch file
for creating hardlink version of source files.</p>
<p>PIL available here: <a href="http://www.pythonware.com/products/pil/" rel="nofollow">http://www.pythonware.com/products/pil/</a></p>
Directory Walking File Renamer (Python)
2008-12-28T08:04:34-08:00mickey Hadickhttp://code.activestate.com/recipes/users/4168585/http://code.activestate.com/recipes/576597-directory-walking-file-renamer/
<p style="color: grey">
Python
recipe 576597
by <a href="/recipes/users/4168585/">mickey Hadick</a>
(<a href="/recipes/tags/directory/">directory</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/rename/">rename</a>).
</p>
<p>Walk through a list of directories and rename the files within those directories based on the directory name and an index value. Useful for managing photos when downloaded from a camera into directories based on the shooting date.</p>