-
-
Save dasrecht/49dae3c72ed2e8a7f164 to your computer and use it in GitHub Desktop.
Perl: Remove all Umlauts and special characters from filenames
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 | |
#=============================================================================== | |
# | |
# FILE: renametree.pl | |
# | |
# USAGE: ./renametree.pl | |
# | |
# DESCRIPTION: rename files and directories in the current tree to | |
# eliminate special characters | |
# | |
# OPTIONS: --- | |
# REQUIREMENTS: --- | |
# BUGS: --- | |
# NOTES: --- | |
# AUTHOR: Felix M. Palmen (fmp), <fmp@palmen.homeip.net> | |
# COMPANY: | |
# VERSION: 1.0 | |
# CREATED: 10.09.2008 15:35:57 CEST | |
# REVISION: --- | |
#=============================================================================== | |
use strict; | |
use warnings; | |
use File::Find (); | |
use File::Copy (); | |
my %replacements = ( | |
'a\xcc\x88' => 'ä', | |
'o\xcc\x88' => 'ö', | |
'u\xcc\x88' => 'ü', | |
); | |
sub rename | |
{ | |
my $name = $_; | |
for (keys(%replacements)) | |
{ | |
$name =~ s/$_/${replacements{$_}}/g; | |
} | |
return if ($name eq $_); | |
if (-e $name) | |
{ | |
my $i = 0; | |
++$i while (-e $name.$i); | |
$name .= $i; | |
} | |
print "renaming: '$File::Find::name' => '$name'\n"; | |
#File::Copy::move($_, $name); | |
} | |
File::Find::finddepth(\&rename, "."); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment