slitaz-dev-tools view baba-scripts/rename.pl @ rev 208
tazdev: clean-up old cmd, up (c)
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Thu Jan 02 14:23:55 2014 +0100 (2014-01-02) |
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);