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

In reply to Re: incrementing the file by Marshall
in thread incrementing the file by abcdefg

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.