Skip to content

Instantly share code, notes, and snippets.

@dasrecht
Forked from kogakure/umlaute.pl
Last active December 3, 2015 12:24
Show Gist options
  • Save dasrecht/49dae3c72ed2e8a7f164 to your computer and use it in GitHub Desktop.
Save dasrecht/49dae3c72ed2e8a7f164 to your computer and use it in GitHub Desktop.
Perl: Remove all Umlauts and special characters from filenames
#!/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