Rename file in the directory.

dwyane123

Member
Joined
Oct 14, 2008
Messages
23
Programming Experience
Beginner
Hi, do you u guys know what is the code to rename a file in a directory,

I have searched and found this:

My.Computer.FileSystem.RenameFile("C:\Test.txt", "SecondTest.txt")

however, it does not work for mine as mine is windows application development. when i put in this code, my.computer is underlined. Any one know the code to rename files in a directory? thanks
 
The above works in all project types, if it doesn't for you then you may have messed something up. Try create a new project and see if it still underlines, if not compare you projects references etc. Is there btw a funny message with the underline?

There is no substitution for the above elsewhere in framework, but System.IO.File.Move method will at least perform a rename operation.
 
thats my code

My.Computer.FileSystem.RenameFile("\My Documents\Receiving List\default.txt", "SecondTest.txt")

it states computer is not a member of my

is there a need to import anything?
 
It's part of Microsoft.VisualBasic assembly, in VB2008 it can't be removed, but I can't recall with the older version you're using. Upload a sample project that contains this error please. I would like to have a look.
 
Hi. This is a small sample of the code. Other than this way is there any other way to rename the file name using other codes?

thanks alot
 

Attachments

  • error in rename.zip
    18 KB · Views: 35
hmm, this is a CF.Net PocketPC device application, not a Windows Forms application, moved the thread to CF General forum. I don't have device projects, so I don't know about MY namespace for those... I did check with Forms, Consoles, WPF and ASP.Net/web services though, and it was valid in all those projects.. :D Actually from documentation it looks like CF doesn't have it.

For other solutions, .Net has all file handling in System.IO namespace, a File.Move operation is a "rename" when folder path is same.
 
Back
Top