Created
February 13, 2009 20:12
-
-
Save kolen/64079 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
# Convert cyrilic characters in file names to transliterated latin symbols. Used for mp3s, for example. | |
use utf8; | |
use Encode; | |
use File::Find; | |
use locale; | |
$fs_encoding = 'utf-8'; | |
@trans=qw( a b v g d e zh z i y k l m n o p r s t u f kh ts ch sh sch _ yi _ e yu ya ); | |
sub trans_char($$) | |
{ | |
return $trans[ord($_[0])-ord('а')] if ($_[1]==0); | |
return uc $trans[ord($_[0])-ord('А')] if ($_[1]==1); | |
} | |
sub trans_str($) | |
{ | |
$_ = $_[0]; | |
s/[а-я]/trans_char($&, 0)/gxe; | |
s/[А-Я]/trans_char($&, 1)/gxe; | |
tr/ёЁ/eE/; #For Mithgol | |
return $_; | |
} | |
sub trans_file($) | |
{ | |
print "-> $_\n"; | |
return if ($_[0] =~ /^\.\.?/); | |
my $f_new = trans_str($_[0]); | |
print "-< $f_new\n"; | |
rename (encode($fs_encoding, $_[0]), $f_new) || warn("cannot rename $_[0] to $f_new"); | |
} | |
$starting_dir = $ARGV[0]; | |
if (!$starting_dir) {$starting_dir = '.'}; | |
finddepth(sub{trans_file(decode($fs_encoding ,$_));}, $starting_dir); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment