vb.net Code:
Dim destinationFolderPath As String = fbCopyTo.SelectedPath
For Each sourceFilePath As String In Me.ListBox1.Items
Dim destinationFilePath As String = IO.Path.Combine(destinationFolderPath, IO.Path.GetFileName(sourceFilePath))
If IO.File.Exists(destinationFilePath) Then
Dim fileName As String = IO.Path.GetFileNameWithoutExtension(sourceFilePath)
Dim fileNumber As Integer = 1
Dim extension As String = IO.Path.GetExtension(sourceFilePath)
destinationFolderPath = IO.Path.Combine(destinationFolderPath, _
String.Format("{0}{1}.{2}", _
fileName, _
fileNumber, _
extension))
While IO.File.Exists(destinationFolderPath)
fileNumber += 1
destinationFolderPath = IO.Path.Combine(destinationFolderPath, _
String.Format("{0}{1}.{2}", _
fileName, _
fileNumber, _
extension))
End While
End If
IO.File.Copy(sourceFilePath, destinationFilePath)
Next