Advertisement
Guest User

Untitled

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