<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Batch-renaming files</title>
	<atom:link href="http://blog.viridian-project.de/2008/07/09/batch-renaming-files/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.viridian-project.de/2008/07/09/batch-renaming-files/</link>
	<description>Leslie P. Polzer on code, music, literature, design and free software business.</description>
	<lastBuildDate>Fri, 09 Dec 2011 14:52:23 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: omid8bimo</title>
		<link>http://blog.viridian-project.de/2008/07/09/batch-renaming-files/comment-page-1/#comment-41366</link>
		<dc:creator>omid8bimo</dc:creator>
		<pubDate>Sat, 27 Feb 2010 16:12:31 +0000</pubDate>
		<guid isPermaLink="false">http://blog.viridian-project.de/?p=85#comment-41366</guid>
		<description>cool pieces of codes</description>
		<content:encoded><![CDATA[<p>cool pieces of codes</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Leslie</title>
		<link>http://blog.viridian-project.de/2008/07/09/batch-renaming-files/comment-page-1/#comment-5736</link>
		<dc:creator>Leslie</dc:creator>
		<pubDate>Sun, 27 Jul 2008 07:34:44 +0000</pubDate>
		<guid isPermaLink="false">http://blog.viridian-project.de/?p=85#comment-5736</guid>
		<description>How cute, it&#039;s self-modifying code.</description>
		<content:encoded><![CDATA[<p>How cute, it&#8217;s self-modifying code.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marco</title>
		<link>http://blog.viridian-project.de/2008/07/09/batch-renaming-files/comment-page-1/#comment-5692</link>
		<dc:creator>Marco</dc:creator>
		<pubDate>Sat, 26 Jul 2008 15:15:43 +0000</pubDate>
		<guid isPermaLink="false">http://blog.viridian-project.de/?p=85#comment-5692</guid>
		<description>Just a small issue with the python example, if run as a script it will rename itself.</description>
		<content:encoded><![CDATA[<p>Just a small issue with the python example, if run as a script it will rename itself.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Fredrik</title>
		<link>http://blog.viridian-project.de/2008/07/09/batch-renaming-files/comment-page-1/#comment-5360</link>
		<dc:creator>Fredrik</dc:creator>
		<pubDate>Thu, 17 Jul 2008 21:14:09 +0000</pubDate>
		<guid isPermaLink="false">http://blog.viridian-project.de/?p=85#comment-5360</guid>
		<description>Python:

&lt;pre lang=&quot;python&quot;&gt;
from os import listdir, rename, path

for i, name in enumerate(listdir(&quot;.&quot;)):
    rename(name, &quot;pysolfc%d%s&quot; % (i+1, path.splitext(name)[1]))
&lt;/pre&gt;

or, a bit too clever perhaps:

&lt;pre lang=&quot;lisp&quot;&gt;
from os import listdir, rename, path

any(rename(name, &quot;pysolfc%d%s&quot; % (i+1, path.splitext(name)[1]))
    for i, name in enumerate(listdir(&quot;.&quot;)))
&lt;/pre&gt;

Python&#039;s penalized by explicit import of subsystems (the number of &quot;built-ins&quot; is relatively small), and less powerful formatting.  But three lines are three lines... ;-)</description>
		<content:encoded><![CDATA[<p>Python:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">os</span> <span style="color: #ff7700;font-weight:bold;">import</span> listdir, rename, path
&nbsp;
<span style="color: #ff7700;font-weight:bold;">for</span> i, name <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">enumerate</span><span style="color: black;">&#40;</span>listdir<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;.&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>:
    rename<span style="color: black;">&#40;</span>name, <span style="color: #483d8b;">&quot;pysolfc%d%s&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>i+<span style="color: #ff4500;">1</span>, path.<span style="color: black;">splitext</span><span style="color: black;">&#40;</span>name<span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>or, a bit too clever perhaps:</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;">from os import listdir<span style="color: #66cc66;">,</span> rename<span style="color: #66cc66;">,</span> path
&nbsp;
any<span style="color: #66cc66;">&#40;</span>rename<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">name</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">&quot;pysolfc%d%s&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: #66cc66;">&#40;</span>i+<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> path<span style="color: #66cc66;">.</span>splitext<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">name</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    for i<span style="color: #66cc66;">,</span> <span style="color: #b1b100;">name</span> in enumerate<span style="color: #66cc66;">&#40;</span>listdir<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;.&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>Python&#8217;s penalized by explicit import of subsystems (the number of &#8220;built-ins&#8221; is relatively small), and less powerful formatting.  But three lines are three lines&#8230; ;-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: one</title>
		<link>http://blog.viridian-project.de/2008/07/09/batch-renaming-files/comment-page-1/#comment-5314</link>
		<dc:creator>one</dc:creator>
		<pubDate>Wed, 16 Jul 2008 12:59:22 +0000</pubDate>
		<guid isPermaLink="false">http://blog.viridian-project.de/?p=85#comment-5314</guid>
		<description>i have a file, temp.txt in folder c:/TMP/Arch
my script is in c:/script/script1.py

i want to rename the file temp.txt with the date and time, but my script rename the file and then move the file in c:/script/

can u tell me pls how to do ? i want the file with new name to remain in c:/TMP/Arch
 
my script 
from time import time, localtime, strftime
time_tuple = localtime(time())
ddate = strftime(&quot;%d.%m.%y-%H;%M;%S&quot;, time_tuple)

ext = &quot;.txt&quot;
file = &#039;c:/TMP/Arhiva/temp.txt&#039;
(basename,ext) = os.path.splitext(file)
os.rename(file, ddate+ext)</description>
		<content:encoded><![CDATA[<p>i have a file, temp.txt in folder c:/TMP/Arch<br />
my script is in c:/script/script1.py</p>
<p>i want to rename the file temp.txt with the date and time, but my script rename the file and then move the file in c:/script/</p>
<p>can u tell me pls how to do ? i want the file with new name to remain in c:/TMP/Arch</p>
<p>my script<br />
from time import time, localtime, strftime<br />
time_tuple = localtime(time())<br />
ddate = strftime(&#8220;%d.%m.%y-%H;%M;%S&#8221;, time_tuple)</p>
<p>ext = &#8220;.txt&#8221;<br />
file = &#8216;c:/TMP/Arhiva/temp.txt&#8217;<br />
(basename,ext) = os.path.splitext(file)<br />
os.rename(file, ddate+ext)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian</title>
		<link>http://blog.viridian-project.de/2008/07/09/batch-renaming-files/comment-page-1/#comment-5015</link>
		<dc:creator>Brian</dc:creator>
		<pubDate>Fri, 11 Jul 2008 21:36:22 +0000</pubDate>
		<guid isPermaLink="false">http://blog.viridian-project.de/?p=85#comment-5015</guid>
		<description>&lt;pre lang=&quot;ruby&quot;&gt;
#!/usr/bin/ruby

require &#039;fileutils&#039;

Dir.glob(ARGV[0]).each_with_index do &#124;fn, i&#124;
  FileUtils.mv(fn, File.join(File.dirname(fn), &quot;pysol#{i+1}&quot; + File.extname(fn)))
end
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#!/usr/bin/ruby</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'fileutils'</span>
&nbsp;
<span style="color:#CC00FF; font-weight:bold;">Dir</span>.<span style="color:#9900CC;">glob</span><span style="color:#006600; font-weight:bold;">&#40;</span>ARGV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">each_with_index</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>fn, i<span style="color:#006600; font-weight:bold;">|</span>
  <span style="color:#CC00FF; font-weight:bold;">FileUtils</span>.<span style="color:#9900CC;">mv</span><span style="color:#006600; font-weight:bold;">&#40;</span>fn, <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">dirname</span><span style="color:#006600; font-weight:bold;">&#40;</span>fn<span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#996600;">&quot;pysol#{i+1}&quot;</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">extname</span><span style="color:#006600; font-weight:bold;">&#40;</span>fn<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

]]></content:encoded>
	</item>
	<item>
		<title>By: sandsmark</title>
		<link>http://blog.viridian-project.de/2008/07/09/batch-renaming-files/comment-page-1/#comment-4955</link>
		<dc:creator>sandsmark</dc:creator>
		<pubDate>Thu, 10 Jul 2008 14:56:15 +0000</pubDate>
		<guid isPermaLink="false">http://blog.viridian-project.de/?p=85#comment-4955</guid>
		<description>man rename</description>
		<content:encoded><![CDATA[<p>man rename</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael Klier</title>
		<link>http://blog.viridian-project.de/2008/07/09/batch-renaming-files/comment-page-1/#comment-4942</link>
		<dc:creator>Michael Klier</dc:creator>
		<pubDate>Thu, 10 Jul 2008 08:36:27 +0000</pubDate>
		<guid isPermaLink="false">http://blog.viridian-project.de/?p=85#comment-4942</guid>
		<description>I haven&#039;t done anything in perl in a while, but your post got me motivated ;-). So here&#039;s a solution in perl:

&lt;pre lang=&quot;perl&quot;&gt;
#!/usr/bin/env perl
use warnings;
use strict;

my $i=1;
foreach $_ (@ARGV) {
    if( $_ =~ /(jpeg&#124;jpg&#124;png&#124;gif)/ ) {
        rename($_, &quot;pysolfc&quot; . $i++ . &quot;.$1&quot;);
    }
}
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>I haven&#8217;t done anything in perl in a while, but your post got me motivated ;-). So here&#8217;s a solution in perl:</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/env perl</span>
<span style="color: #000000; font-weight: bold;">use</span> warnings<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> strict<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #0000ff;">$_</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@ARGV</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$_</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">/(jpeg|jpg|png|gif)/</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">rename</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$_</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;pysolfc&quot;</span> . <span style="color: #0000ff;">$i</span><span style="color: #339933;">++</span> . <span style="color: #ff0000;">&quot;.$1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
	</item>
	<item>
		<title>By: codemac</title>
		<link>http://blog.viridian-project.de/2008/07/09/batch-renaming-files/comment-page-1/#comment-4939</link>
		<dc:creator>codemac</dc:creator>
		<pubDate>Wed, 09 Jul 2008 23:25:06 +0000</pubDate>
		<guid isPermaLink="false">http://blog.viridian-project.de/?p=85#comment-4939</guid>
		<description>Yea, if you&#039;re looking for the ultimate in renaming, you should check out zmv.</description>
		<content:encoded><![CDATA[<p>Yea, if you&#8217;re looking for the ultimate in renaming, you should check out zmv.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael Klier</title>
		<link>http://blog.viridian-project.de/2008/07/09/batch-renaming-files/comment-page-1/#comment-4925</link>
		<dc:creator>Michael Klier</dc:creator>
		<pubDate>Wed, 09 Jul 2008 15:19:45 +0000</pubDate>
		<guid isPermaLink="false">http://blog.viridian-project.de/?p=85#comment-4925</guid>
		<description>@smoon, nice, after seeing your solution I am wondering what led me to use printf. Seems the first thing that came to my mind wasn&#039;t the most obvious ;-).</description>
		<content:encoded><![CDATA[<p>@smoon, nice, after seeing your solution I am wondering what led me to use printf. Seems the first thing that came to my mind wasn&#8217;t the most obvious ;-).</p>
]]></content:encoded>
	</item>
</channel>
</rss>

