slitaz-dev-tools diff baba-scripts/reninc.pl @ rev 309

Remove ashism ==
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Feb 26 08:23:49 2019 +0100 (2019-02-26)
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/baba-scripts/reninc.pl	Tue Feb 26 08:23:49 2019 +0100
     1.3 @@ -0,0 +1,45 @@
     1.4 +#! /usr/bin/perl
     1.5 +#check for help
     1.6 +chomp (my $workdir = `pwd`);
     1.7 +chomp (my $scriptname=`basename "$0"`);
     1.8 +scalar @ARGV > 0 || die <<EOT1;
     1.9 +Usage : $scriptname [-psdn [argument]] directory|here
    1.10 +
    1.11 +Options :
    1.12 +    -p prefix
    1.13 +    -s suffix
    1.14 +    -d starting_base_number
    1.15 +    -n length of number part (1: one number, 2: two numbers, etc)
    1.16 +
    1.17 +Parameters :
    1.18 +    directory : complete path of directory to process, or "here" for
    1.19 +                working directory
    1.20 +                ($workdir)
    1.21 +EOT1
    1.22 +#check arguments
    1.23 +my ($pref, $suff, $start, $num_length) = ('', '', 1, 1);
    1.24 +while (scalar @ARGV > 0)
    1.25 +{
    1.26 +	my $arg = shift @ARGV;
    1.27 +	if ($arg eq "-p") { $pref = shift @ARGV; next; }
    1.28 +	elsif ($arg eq "-s") { $suff = shift @ARGV; next; }
    1.29 +	elsif ($arg eq "-d") { $start = shift @ARGV; next; }
    1.30 +	elsif ($arg eq "-n") { $num_length = shift(@ARGV) - 1; next; }
    1.31 +	elsif (-d $arg) { $dir = shift @ARGV; next; }
    1.32 +	elsif ($arg eq "here") { $dir = $workdir; next; }
    1.33 +}
    1.34 +#main routine
    1.35 +chdir $dir;
    1.36 +foreach (<*>)
    1.37 +{
    1.38 +	my $counter = $start;
    1.39 +	my ($purename, $ext) = (m/^(.+?)\.([^\.]+)$/);
    1.40 +	for (my $n = 1; $n <= $num_length; $n++)
    1.41 +	{
    1.42 +		last if ($num_length eq 0);
    1.43 +		if ($start < 10**$n) { $counter = '0'.$counter; }
    1.44 +	}
    1.45 +	$start++;
    1.46 +	print "Rename \"$_\" in $pref$counter$suff.$ext\n";
    1.47 +	rename $_, $pref.$counter.$suff.'.'.$ext;
    1.48 +}