title: Function to increment filename
body: <p>I'm trying to make a function that can increment a filename.
  If last char of the string is a number then increment it.
  If last char is a letter then add _1 or _2 or _3(increment this also).
  I have to be sure the filename is unique but i cannot use datetime inside filename because all the filenames must be &lt;32 chars without extension.</p>
  
  <pre><code>EX: Apple_99.txt =&gt;Apple_100
  Ex: Apple_173 =&gt; Apple_174
  EX: This_is_my_first_text.txt =&gt; This_is_my_first_text_1.txt
  Ex: This_is_my_first_text_9.txt =&gt; This_is_my_first_text_10.txt
  </code></pre>
  
  <p>I need to use this in order to rename a file an then upload it to a ftp server.
  I've found a function that can do something like this but it only works if the filename contains only uppercase.How can I modify this function in order to access lowercase an uppercase string?</p>
  
  <p>Here is the function:</p>
  
  <pre><code>    function IncStr(Str: String; Amount: Integer; Index: Integer = -1): String;
      const
       MIN_VAL = 65; // 'A'
       MAX_VAL = 90; // 'Z'
      var
       Digit, ToAdd, ToCarry: Integer;
      begin
  
       if (Index = 0) and (Amount &gt; 0) then
        begin
         Result := Char(MIN_VAL + Amount - 1) + Str;
         Exit;
        end;
  
       if Index = -1 then Index := Length(Str);
  
       ToCarry := 0;
  
       Digit := Ord(Str[Index]);
  
       while not (Digit in [MIN_VAL..MAX_VAL]) do
        begin
         Dec(Index);
         Digit := Ord(Str[Index]);
        end;
  
       ToAdd := Digit + Amount;
  
       while (ToAdd &gt; MAX_VAL) do
        begin
         Dec(ToAdd, 26);
         Inc(ToCarry);
        end;
  
       Result := Str;
       Result[Index] := Char(ToAdd);
  
       if (ToCarry &gt; 0) then
        Result := IncStr(Result, ToCarry, Index - 1);
  
      end;
  
  
      procedure TForm1.Button1Click(Sender: TObject);
      var
       S: String;   // holds string to increment
       C: Integer;  // amount to increment by
      begin
       // make sure that Edit1 starts with a valid character
       // i.e. 'A' to 'Z'
       S := Edit1.Text;
       C := StrtoIntDef(Edit2.Text, 0);
       // test it, place result in Edit3
       Edit3.Text := IncStr(S, C);
       {
         Example data:
  
           Edit1 := AAZ
           Edit2 := 2
         = Edit3 := ABB
  
           Edit1 := BZY
           Edit2 := 3
         = Edit3 := CAB
  
           Edit1 := ZZZ
           Edit2 := 1
         = Edit3 := AAAA
  
           Edit1 := AA-AC
           Edit2 := 3
         = Edit3 := AA-AF
  
           Edit1 := AA/Z
           Edit2 := 5
         = Edit3 := AB/E
  
         ... etc
  
         Here's one to try too :-)
           Edit1 := ZZZ
           Edit2 := 264172
       }
      end;
  </code></pre>
  
  <p>Thank you!</p>