Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Dec 27th, 2010  |  syntax: Perl  |  size: 0.70 KB  |  views: 45  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/usr/bin/perl -w
  2. #
  3. # regmv - Rename files using a regular expression
  4. #
  5. # This program renames files by using a regular expression to
  6. # determine their new name.
  7. #
  8. # Usage: regmv file [file ...] regexp
  9. #
  10. # $Id: regmv,v 1.1 1998/10/14 17:07:55 blrfl Exp $
  11. #
  12.  
  13. sub at_clean()
  14. {
  15.     my $message = $@;
  16.     $message =~ s|\s+at /.*$||s;
  17.     return $message;
  18. }
  19.  
  20. (@ARGV > 1)
  21.     || die "Usage: regmv [options] file [file ...] regexp\n";
  22.  
  23. my $expr = pop @ARGV;
  24.  
  25. $_ = 'SomeValue';
  26. eval "\$_ =~ $expr";
  27. die "Yuck: " . at_clean() if $@;
  28.  
  29. foreach (@ARGV)
  30. {
  31.     my $old = $_;
  32.  
  33.     eval "\$_ =~ $expr";
  34.  
  35.     next if $_ eq $old;
  36.  
  37.     (rename $old, $_)
  38.         || die "Rename failed: $!\n";
  39. }