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

makegraphs: tune cpuinfo
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Jan 15 08:08:28 2021 +0000 (2021-01-15)
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);