Heth/Image filenames æøåÆØÅ

From Teknologisk videncenter
Revision as of 11:35, 29 July 2011 by Heth (talk | contribs) (Created page with "Changing filenames including æøåÆØÅ to UTF8 from UNICODE <source lang=perl> use warnings; use strict; use File::Find; use File::Find; my ($ae,$ao,$aa,$AE,$AO,$AA,$om,$mo...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Changing filenames including æøåÆØÅ to UTF8 from UNICODE

use warnings;
use strict;
use File::Find;

use File::Find;

my ($ae,$ao,$aa,$AE,$AO,$AA,$om,$more) = (0,0,0,0,0,0,0,0);
    find( {wanted=> \&wanted, no_chdir => 1}, '/var/www/wiki/images' );
        print "ae = $ae\n";
        print "ao = $ao\n";
        print "aa = $aa\n";
        print "AO = $AO\n";
        print "ó  = $om\n";
 print "Ialt ", $ae+$ao+$aa+$AE+$AO+$AA+$om, " filer der er $more filer med flere\n";
    sub wanted {
                my $f = $_;
                my $file = $f;
                my $flag=0;
                if ( $f =~ /\303/ ) {
                        #print "file $f\n";
                        if ( $f =~ s/\303\203\302\246/\303\246/g ) {
                                $ae++; $flag++;
                                print "Renaming to $f\n";
rename($file, $f) or warn "Couldn't rename $file to $f : $!\n";
                        }
                        if ( $f =~ s/\303\203\302\270/\303\270/g ) {
                                $ao++; $flag++;
                                print "Renaming to $f\n";
rename($file, $f) or warn "Couldn't rename $file to $f : $!\n";
                        }
                        if ( $f =~ s/\303\203\302\245/\303\245/g ) {
                                $aa++; $flag++;
                                print "Renaming to $f\n";
rename($file, $f) or warn "Couldn't rename $file to $f : $!\n";
                        }
                        #if ( $f =~ /\303\203\357\277\275/ ) {
                        if ( $f =~ s/\303\203\302\230/\303\230/g ) {
                                $AO++; $flag++;
                                print "Renaming to $f\n";
rename($file, $f) or warn "Couldn't rename $file to $f : $!\n";
                        }
                        if ( $f =~ s/\303\203\302\263/\303\263/g ) {
                                $om++; $flag++;
                                print "Renaming to $f\n";
rename($file, $f) or warn "Couldn't rename $file to $f : $!\n";
                        }
                        if ( $flag == 0) {
                                #print ("---> $f not marked..\n");
                        }
                        if ($flag > 1) { $more++;}

                 }
}