Rename to a numbered file name
Apr. 8th, 2005 03:29 pmThis Perl script renames buff-out.ogf to b###.ogf, where ### is the next higher number after the highest numbered b###.ogf file. It is used for keeping an archive of submitted distributed.net OGR packets.
#!perl -w
use strict;
require 5.004;
use DirHandle;
my $TEMPDIR = 'c:\\temp';
my $dh = new DirHandle $TEMPDIR;
defined $dh or die "Error opening directory $TEMPDIR: $!\n";
my $highnum = 0;
while (defined($_ = $dh->read)) {
if (/b(\d+).ogf/i) {
$1 > $highnum and $highnum = $1;
}
}
my $nextindex = $highnum + 1;
print "Highest = $highnum, Next index = $nextindex\n";
rename "$TEMPDIR\\buff-out.ogf", "$TEMPDIR\\b$nextindex.ogf"
or die "Error renaming file: $!\n";
__END__