473,378 Members | 1,577 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Rename multiple files like windows does...

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!!!
--
Salute by the First Time!
Nov 21 '05 #1
5 4431
"Rothariger" <Ro********@msn.com> schrieb:
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #2
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...
--
Salute by the First Time!
"Herfried K. Wagner [MVP]" wrote:
"Rothariger" <Ro********@msn.com> schrieb:
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #3
On Mon, 22 Aug 2005 12:48:06 -0700, Rothariger wrote:
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.
Nov 21 '05 #4
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.Igno rePatternWhitespace) _
Or
System.Text.RegularExpressions.RegexOptions.Ignore Case)
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" <Ro********@msn.com> escreveu na mensagem
news:18**********************************@microsof t.com...
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!!!
--
Salute by the First Time!


Nov 21 '05 #5
"Rothariger" <Ro********@msn.com> schrieb:
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jay at SCA | last post by:
I've been having the following issue with a windows service I've created in vb.net (.net fw 1.1): Basically, my service monitors a folder for the creation of any new files of a particular type...
5
by: Tony Meyer | last post by:
On Windows, if I do os.rename(old, new) where old is a file that is in-use (e.g. python itself, or a dll that is loaded), I would expect that an error would be raised (e.g. as when os.remove is...
10
by: Don Curtis | last post by:
I have a C# client app that sometimes needs to do thousands of specialized file renames of files on a file server in the same domain. If the files reside locally on the client machine, the renames...
3
by: rn5a | last post by:
An inquisitive question...... A ListBox lists all the directories & files residing in a directory on the server. Assume that the ListBox lists 2 directories & 4 files. Also assume that one of...
3
by: Luciano | last post by:
I have been programing in PHP recently. For this reason, I have lots of basic doubts. Let's see one of then. I'm developing in the localhost, so safety issues are not important. I have a script...
2
by: =?iso-8859-1?b?cultaQ==?= | last post by:
Hi, I would like to rename files (jpg's ones) using a text file containing the new names... Below is the code that doesn't work : ***** #!/usr/bin/python #-*- coding: utf-8 -*- from os...
1
by: lukas | last post by:
hello, i recently had the job of having to rename about 200 files. The source for the renaming was a bunch of names in a file. I know next to nothing when it comes to bash scripting (which would...
7
by: Bob Altman | last post by:
Using VS 2008 SP1, is there a way to rename a CSS style and all of the references to that style (short of doing a global find-and-replace in the code)? You'd think that the Manage Styles and Apply...
1
by: achotto | last post by:
hi, i try to upload a multiple image files. after that i will rename the files name. the problem is when i upload a 2 or more same files name exp-goal.jpg, it will return "files already exist". ok...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.