Visual Basic Programming Code Examples Visual Basic > Files Directories Drives Code Examples Adding A Number To A Filename Adding A Number To A Filename Function NumerateFileName(FileName As String, _ NumberToAdd As Long) As String 'Dimension some variables. Dim TMP As String Dim Count As Long 'First strip the extension. TMP = FileName For Count = Len(TMP) To 1 Step -1 If Mid$(TMP, Count, 1) = "." Then TMP = Left$(TMP, Count - 1) Exit For End If Next Count 'Then add the number. TMP = TMP + CStr(NumberToAdd) 'Then put the extnesion back on and return it. For Count = 1 To Len(FileName) If Mid$(FileName, Count, 1) = "." Then NumerateFileName = TMP + Right$(FileName, _ Len(FileName) - Count + 1) Exit For End If Next Count End Function