Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use File::Find;
- use strict;
- use warnings;
- finddepth (\&recursive, "./");
- sub recursive
- {
- push @path, "$File::Find::dir/";
- push @files, $_;
- }
- @files = File::Spec->no_upwards( @files );
- my @newname;
- foreach my $file (@files)
- {
- my (@parts, @name);
- push @name, split(/\./,$file);
- foreach my $piece (@name)
- {
- unless ( ($piece =~ /[[:alpha:]]/ && $piece =~ /[[:digit:]]/) ){
- $piece = substr $piece, 0, 1;
- }
- push @parts, $piece;
- }
- push @newname, join('.',@parts);
- }
- my %h = ();
- @newname = map { s/(\d*)$/$1 + 1/e while $h{$_}; $h{$_}++; $_ } @newname;
- pop @path;
- my @from = @path;
- for my $i (0..$#path) { $from[$i] .= $files[$i] } \@from;
- my @to = @path;
- for my $i (0..$#path) { $to[$i] .= $newname[$i] } \@to;
- sub first_char { substr( shift, 0, 1) }
- sub assemble ( join '.', @_ }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement