#!/usr/local/bin/perl use warnings; use strict; use File::Copy qw/mv/; sub get_og_files { my @og_files; opendir(DIR, '.') or die $!; while (readdir(DIR)) { next if ($_ =~ m/^\./); push @og_files, $_; } closedir(DIR); return @og_files; } use constant { C_O => '', }; sub unixize_file_names { my @og_files = @_; my @new_files; foreach (@og_files) { if ($_ =~ /^[0-9]+\./) { $_ =~ s/\.//; } $_ =~ s/ - /_/g; $_ =~ s/ /_/g; $_ =~ s/c\+\+/cxx/g; $_ =~ s/C\+\+/CXX/g; $_ =~ s/[\x83\x84\x85\x86]/a/g; # âäàå $_ =~ s/[]/A/g; # ÄÅ $_ =~ s/\x91/ae/g; # æ $_ =~ s/\x92/AE/g; # Æ $_ =~ s/\x87/c/g; # ç $_ =~ s/\x80/C/g; # Ç $_ =~ s/[\x82\x88\x89\x8a]/e/g; # éêëè # $_ =~ s/[ÉÈÊË]/E/g; $_ =~ s/[\x8b\x8c\x8d]/i/g; # ïîì # $_ =~ s/[ÏÎÌ]/I/g; # $_ =~ s/[ôöò]/o/g; $_ =~ s/[\x93\x94\x95]/o/g; # ôöò # $_ =~ s/[ÿ]/y/g; $_ =~ s/ü/u/g; $_ =~ s/Ü/U/g; $_ =~ s/[^A-Za-z0-9\._]+//g; $_ = lc($_); push @new_files, $_; } return @new_files; } sub main { my @og_files; my @new_files; my @files; @og_files = get_og_files(); @new_files = unixize_file_names(@og_files); while (@og_files || @new_files) { $files[0] = shift @og_files; $files[1] = shift @new_files; if (@ARGV == 1 && $ARGV[0] eq '-R' && -d $files[0]) { chdir($files[0]) or die $!; main(); chdir('../'); } next if (-e $files[1]); # mv($files[0], $files[1]) or print STDERR $! . "\n"; print "'". $files[0] . "' -> '" . $files[1] . "'\n"; } return; } main(); __END__