#!/usr/local/bin/perl -w # Clean accents - clean accents from a filesystem use utf8; # Tell Perl that this file is written in UTF-8 use Text::Unaccent; use File::Find; use Unicode::Normalize 'normalize'; use Encode; my($path)=shift(@ARGV) || die("Please specify the path to clean on the command line\n"); # A table of replacement strings. Add as neccessary my $replace = { "ß" => "ss", "Å" => "A", "œ" => "oe", }; find(\&wanted, $path); sub wanted { my($old)=normalize('KC',Encode::decode("UTF-8",$File::Find::name)); my($new)=$old; foreach my $replacement (keys %$replace) { $new=~s|$replacement|$replace->{$replacement}|g; } $new=unac_string("UTF-8",$old); if($old ne $new) { if($new ne "") { print(STDERR "Renaming $old to $new\n"); rename($File::Find::name,"$new") || print (STDERR "Couldn't rename $File::Find::name to $new: $!\n"); } else { print("Not renameing $File::Find::name: Couldn't generate new name.\n"); } } }