useful script, file renamer in python

Kristian Hermansen kristian.hermansen-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org
Mon May 28 14:02:16 EDT 2007


So, Jabra's script didn't really make nice file names as far as I
could tell, which was the point of my original script, to covert file
names into something less nasty.  Here is an example of the rename
command, which is a perl program distributed standard on at least all
Debian/Ubuntu and probably other distros as well...

khermans at khermans-laptop:/tmp$ touch '!@#$RT>>K:"FZA!@%(_+HGN.foo'
khermans at khermans-laptop:/tmp$ touch 'KJKSHHHWiddojq d kajdkd
k)0-=e=-sS|D}swlamdS!@``~.ffaa.a.df.6.7.&.@#^&(_+_)(*&^%$#@!.bar'
khermans at khermans-laptop:/tmp$ rename -n "s/[^A-Za-z0-9\.]/_/g;
y/A-Z/a-z/" *.foo *.bar
!@#$RT>>K:"FZA!@%(_+HGN.foo renamed as ____rt__k__fza______hgn.foo
KJKSHHHWiddojq d kajdkd
k)0-=e=-sS|D}swlamdS!@``~.ffaa.a.df.6.7.&.@#^&(_+_)(*&^%$#@!.bar
renamed as kjkshhhwiddojq_d_kajdkd_k_0__e__ss_d_swlamds_____.ffaa.a.df.6.7._.__________________.bar

So rename takes perlexpr's as arguments.  And you can combine multiple
directives with ';', which I didn't known until I asked in #perl.
Good stuff...
-- 
Kristian Hermansen

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.






More information about the Discuss mailing list