Renaming files

J

John

Hi

How can I rename a file on disk in vb,net? Basically I am looking for vb.net
equivalent of the vba Name command.

Thanks

Regards
 
D

Dale Levesque

My.Computer.Filesystem.RenameFile


or

' How to move / rename a file.
Private Sub button6_Click(sender As Object, e As System.EventArgs)

Dim fi As New FileInfo("myImage.gif")

fi.MoveTo("myImage2.gif")

End Sub 'button6_Click
 
K

kimiraikkonen

Hi

How can I rename a file on disk in vb,net? Basically I am looking for vb.net
equivalent of the vba Name command.

Thanks

Regards

An alternative way:

' Specify file that you want to rename
Dim file As New System.IO.FileInfo("c:\test.txt")

' Copy current file with a new file name
file.CopyTo("c:\new_test.txt")

' Delete old file
file.Delete()

but i think "My" namespace is much easy-to-use.
 
H

Herfried K. Wagner [MVP]

John said:
How can I rename a file on disk in vb,net? Basically I am looking for
vb.net equivalent of the vba Name command.

Take a look at these functions/methods:

'Rename'
'My.Computer.FileSystem.RenameFile'
'My.Computer.FileSystem.RenameDirectory'
'File.Move'
'Directory.Move'
 

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

Top