Batch rename files with Perl regex substitutions


/ Published in: Perl
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.