CCL Home Page
Up Directory CCL oneup.pl
#!/usr/bin/perl

if($#ARGV < 0) {
    die "Usage: onup.pl [dir] nameNNNN.html\n";
}
elsif ($#ARGV == 0) {
    $dir = ".";
    $file = $ARGV[0];
}
elsif ($#ARGV == 1) {
    $dir = $ARGV[0];
    $file = $ARGV[1];
}

if($file =~ /^([a-z]+)(\d+)\.html$/) {
    $fname = $1;
    $fnumber = $2;
}
else {
    die "cannot parse file name $file";
}

$numlen = length($fnumber);
$format = "%0" . $numlen . "d"; 

opendir(DIR, $dir) || die "Cannot open directory $dir for reading\n";

$maxnum = 0;

while($entry = readdir(DIR)) {
    if($entry =~ /^$fname(\d+)\.html$/ ) {
	print STDOUT "$entry\n";
	if($1 > $maxnum) {
	    $maxnum = $1;
	}
    }
}

for ($i = $maxnum; $i >= $fnumber; $i--) {
    $from = $dir . "/" . $fname . sprintf($format, $i) . '.html';
    $to = $dir . "/" . $fname . sprintf($format, $i+1) . '.html';
    system("mv $from $to");
    print STDOUT "Moved file $from, to file $to\n";
}


Modified: Sun Feb 10 12:41:31 2002 GMT
Page accessed 2674 times since Mon Feb 3 15:33:07 2003 GMT