Renaming a File

sathya.cs

Active member
Joined
May 24, 2009
Messages
31
Programming Experience
Beginner
While Renaming a File Using the Code "
VB.NET:
My.Computer.FileSystem.RenameFile(File, "NewName")
" , It say that file could not be found...?Wat to do?
 
Filename i am passing is 100% correct cause for testing purpose i m using FileBrowserDialgo to select the File...
 
Here's what I did: I created a text file: C:\Test.txt and typed some random chars it in and saved it.

I then created a new WinForms app, added a button and put this code in:
VB.NET:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    My.Computer.FileSystem.RenameFile("C:\Test.txt", "Test1.txt")
End Sub
I checked my C: drive and sure enough, the file was renamed.
 
So then it's something else going on with your code, it means that after the file is renamed somewhere else you're still trying to use the old name or something.
 
Back
Top