slitaz-dev-tools view baba-scripts/rename.pl @ rev 120
tazwikiss/wkp_Admin: shrink to 4K, add section separators
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sun Jun 19 14:03:36 2011 +0200 (2011-06-19) |
parents | |
children |
line source
1 #! /usr/bin/perl
2 $testmode = 0; #false
3 if ($ARGV[0] eq '-t') {
4 $testmode = 1; #true
5 shift;
6 }
7 ($regexp = shift @ARGV) || die "Usage: rename [-t] perlexpr [filenames]\n-t : option to test action (nothing really done)\n";
8 if (!@ARGV) {
9 @ARGV = <STDIN>;
10 chomp(@ARGV);
11 }
12 print "Test mode\n" if ($testmode);
13 foreach $_ (@ARGV) {
14 $old_name = $_;
15 eval $regexp;
16 die $@ if $@;
17 unless ($old_name eq $_) {
18 print "$old_name -> $_\n";
19 rename($old_name, $_) unless $testmode;
20 }
21 }
22 exit(0);