Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.98 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use File::Find;
  3.  
  4. use strict;
  5. use warnings;
  6.  
  7. finddepth (\&recursive, "./");
  8.  
  9. sub recursive
  10.     {
  11.         push @path, "$File::Find::dir/";
  12.         push @files, $_;
  13.     }
  14.  
  15. @files = File::Spec->no_upwards( @files );
  16. my @newname;
  17. foreach my $file (@files)
  18.     {
  19.         my (@parts, @name);
  20.         push @name, split(/\./,$file);
  21.  
  22.         foreach my $piece (@name)
  23.             {
  24.                 unless ( ($piece =~ /[[:alpha:]]/ && $piece =~ /[[:digit:]]/) ){
  25.                     $piece = substr $piece, 0, 1;
  26.                 }
  27.                 push @parts, $piece;
  28.             }
  29.         push @newname, join('.',@parts);
  30.     }
  31.  
  32. my %h = ();
  33. @newname = map { s/(\d*)$/$1 + 1/e while $h{$_}; $h{$_}++; $_ } @newname;
  34.  
  35. pop @path;
  36.  
  37. my @from = @path;
  38. for my $i (0..$#path) { $from[$i] .= $files[$i] } \@from;
  39.  
  40. my @to = @path;
  41. for my $i (0..$#path) { $to[$i] .= $newname[$i] } \@to;
  42.  
  43.  
  44. sub first_char { substr( shift, 0, 1) }
  45. sub assemble ( join '.', @_ }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement