Rename multiple files like windows does...

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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!!!
 
Rothariger said:
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..

Check out VB.NET's 'Rename' function, which can be used to rename files and
directories.
 
may be i didnt explain very well...

but i was talking about of doing automatically... rename all the files
automatically... i was using the system.io.file.move, but then i must to
check if the file exists and make it automatically... but i was thinking that
may be the windows api make it automatically...
 
may be i didnt explain very well...

but i was talking about of doing automatically... rename all the files
automatically... i was using the system.io.file.move, but then i must to
check if the file exists and make it automatically... but i was thinking that
may be the windows api make it automatically...

Nope. The behavior you describe is programmed in the shell, not the API; so
you must program it yourself.
 
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!!!
 
Rothariger said:
but i was talking about of doing automatically... rename all the files
automatically... i was using the system.io.file.move, but then i must to
check if the file exists and make it automatically... but i was thinking
that
may be the windows api make it automatically...

AFAIK the .NET Framework doesn't provide a method for automatic renaming.
You'll have to implement this behavior yourself.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top