Posted By

iblis on 08/17/08


Tagged

files administration rename


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

icecreamboyy


Batch rename files with Perl regex substitutions


 / Published in: Perl
 

  1. #!/usr/bin/env perl -w
  2. use strict;
  3.  
  4. # Batch rename files with Perl regex substitutions
  5. # Perl administration files rename
  6. #
  7. # Larry Wall's filename fixer: recipe 9.9 in Perl Cookbook
  8.  
  9. $op = shift
  10. or die "Usage: $0 expr [files]\n";
  11. chomp(@ARGV = <STDIN>) unless @ARGV;
  12. for (@ARGV) {
  13. $was = $_;
  14. eval $op;
  15. die $@ if $@;
  16. rename($was, $_) unless $was eq $_;
  17. }
  18.  

Report this snippet  

You need to login to post a comment.