Use a function (below) that I developed for a mine program. I've used that
to rename nodes in a treeview, but you can adapt to check for folders
instead a treenode.
Use:
ParentTreeNode: is a treeview (you can change it to a folder, but you will
need to adapt de code inside function to folder, too)
DefaultName: is the name the user typed in your programa (in you example,
"file")
Change it as well

)
Public Function GenerateNewNodeName(ByVal ParentTreeNode As TreeNode,
ByVal DefaultName As String) As String
Dim i As Integer
Dim lngHighNumber As Long
Dim strNewName As String
If ParentTreeNode.Nodes.Count = 0 Then
Return DefaultName
Else
Dim strRegex As String = "/" & DefaultName & "/|/" & DefaultName
& "\s+\([0-9]*\)/"
strRegex = strRegex.Replace(" ", "\s")
Dim options As System.Text.RegularExpressions.RegexOptions =
((System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace) _
Or
System.Text.RegularExpressions.RegexOptions.IgnoreCase)
Dim cRegExp As System.Text.RegularExpressions.Regex = New
System.Text.RegularExpressions.Regex(strRegex, options)
Dim cMatches As System.Text.RegularExpressions.MatchCollection
Dim cMatch As System.Text.RegularExpressions.Match
Dim tnodNode As TreeNode
Dim strMatchValue As String
Dim strNodeNames As String
Dim cString As New Text.StringBuilder
Dim blnFound As Boolean
'transfer all nodes to a string
cString.Remove(0, cString.Length)
For Each tnodNode In ParentTreeNode.Nodes
cString.Append("/")
cString.Append(tnodNode.Text)
cString.Append("/")
Next
strNodeNames = cString.ToString
'check for matches
cMatches = cRegExp.Matches(strNodeNames)
'initializes the return
strNewName = DefaultName
'find the new name
i = -1
While True
i = i + 1
blnFound = False
For Each cMatch In cMatches
If i = 0 Then
strNewName = DefaultName
Else
strNewName = DefaultName & " (" & i & ")"
End If
If cMatch.Value.Replace("/", "") = strNewName Then
blnFound = True
Exit For
End If
Next
If Not blnFound Then Return strNewName
End While
'return default
Return strNewName
End If
End Function
"Rothariger" <
[email protected]> escreveu na mensagem
Hello....
i want to know if its posible to rename multiple files like windows does..
example:
file zzzzzzz.doc
file asdasd.doc
file esfsefse.doc
if you select the three files and rename it, windows put this way..
file(1).doc
file(2).doc
file(3).doc
is there any vb.net way of doing this?
thanks!!!