Time for you to look into recursion.
The above code has not been checked, but that is, in general, what you want to do.Code:Public Function CheckAndGenerateUniqueCopyName(path As String, Optional seed As Integer = 1) As String 'Check if the supplied path exists If System.IO.File.Exists(path) Then 'The path exists so lets append the seed to the end of it path &= "(" & seed & ")" 'Increment the seed value for the next iteration seed += 1 'Call the same method with the new parameters until a result is found path = CheckAndGenerateUniqueCopyName(path, seed, False) End If Return path End Function




Reply With Quote