Sub checkfilename(dir As String,filename As String, lastint As Int,lastfilename As String) As String
Dim filename2(2) As String = Regex.Split("\.",filename)
Dim filename3 As String = filename
If File.Exists(dir,lastfilename) = True Then
lastint = lastint +1
lastfilename = filename2(0) & "(" & lastint & ")" & "." & filename2(1)
checkfilename(dir,filename3,lastint,lastfilename)
Else
Return lastfilename
End If
End Sub