slitaz-dev-tools view baba-scripts/rename.pl @ rev 231

may resize qrcode
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Jun 26 09:27:03 2014 +0200 (2014-06-26)
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);