Renaming files

  • Thread starter Thread starter John
  • Start date Start date
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
 
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
 
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.
 
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'
 
Back
Top