Skip to content

Instantly share code, notes, and snippets.

@hikiko hikiko/greeklish.pl
Last active Mar 16, 2019

Embed
What would you like to do?
old script - not tested recently - convert greek to latin fnames (?)
#!/usr/bin/perl
use strict;
use Encode;
use File::Copy;
my $dir;
my @files;
my $file;
my $initfile;
my $flag;
$dir=$ARGV[0];
if ( -d $dir ) {
opendir (DIR,$dir) or die $!;
@files = (readdir DIR) or die $!;
closedir (DIR) or die $!;
foreach ( @files ) {
next if ( $_ eq "." || $_ eq ".." );
$file = $_;
$initfile = $_;
$flag = decode ("utf8",$_,Encode::FB_QUIET);
if ( $flag ) {
$file = encode("iso-8859-7",$flag);
}
$file =~ s/\s/_/g;
$file =~ s/θ/th/g;
$file =~ s/Θ/th/g;
$file =~ s/ψ/ps/g;
$file =~ s/Ψ/ps/g;
$file =~ tr/ΑΒΓΔΕΖΗΙΚΛΜΝΞΟΠΡΣΤΥΦΧΩΆΈΉΊΎΌΏΪΫαβγδεζηικλμνξοπρστυφχωάέήίύόώϋϊΰΐς/abgdeziiklmnxoprstyfhoaeiiyooiyabgdeziiklmnxoprstyfhoaeiiyooyiyis/;
$file =~s/_-_/-/g;
$file = "\L$file";
move("$dir$initfile","$dir$file") || die $!;
if ( $initfile eq $file ) {
print "Filename $initfile has not been changed.\n";
}
else {
print "Filename $initfile has been changed to $file.\n";
}
}
}
else {
print "Dir not found.\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.