http://qs321.pair.com?node_id=955462


in reply to incrementing the file

This is another approach. Read the file names in the output directory, filter out the ones that aren't really simple files (maybe there is some directory with a similar name), get the revision numbers of those files, get the max revision number and then add one to that.

#!/usr/bin/perl -w use strict; use List::Util qw(max); # List::Util is a core module # that means you don't have to # install it - its already there. my $output_dir = 'C:/TEMP'; my $program_root_name = "some_prog"; opendir DIR, $output_dir or die "cannot open $output_dir for reading $!"; my @current_numbers = map { /^$program_root_name(\d+)$/ ? $1 : () } # just the numbers grep{ -f "$output_dir/$_"}readdir DIR; # only "real" files # not directories closedir DIR; # purely optional foreach (@current_numbers) #intermediate print routine... { print "$output_dir/$program_root_name$_ exists!\n"; } my $max_cur_number = max(@current_numbers); my $new_max = ++$max_cur_number; print "The next highest number is $new_max\n"; print "Full name of next file in sequence would be: ". "$output_dir/$program_root_name$new_max\n"; __END__ The above prints: Note: I made the dummy files: some_prog1 and some_prog3... C:/TEMP/some_prog1 exists! C:/TEMP/some_prog3 exists! The next highest number is 4 Full name of next file in sequence would be: C:/TEMP/some_prog4