How do i rename a file using vb 2005

Hi all i am wanting to rename a file after it has been copied, i have already got the copied to copy it i just need to rename is now

Thanks in advance
awolarczukAsked:
Who is Participating?
 
Wayne Taylor (webtubbs)Connect With a Mentor Commented:
IO.File.Move("C:\Path\OldFileName.txt", "C:\Path\NewFilename.txt")

Wayne
0
 
aherpsCommented:
  Dim fi As New FileInfo("myFile.doc")
   
   fi.MoveTo("myFile2.doc")
0
 
MTEXXConnect With a Mentor Commented:
Don't forget the eternal excpetions:


Dim prevFilespec As String = "C:\temp\foofie.txt"
Dim newFilespec As String = "C:\temp\foofieXYZ.log"
Try
    System.IO.File.Move(prevFilespec, newFilespec)
Catch ex As Exception
    Console.WriteLine("caught exception: " + ex.ToString)
End Try

Open in new window

0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
Wayne Taylor (webtubbs)Commented:
>>Don't forget the eternal excpetions:

One would assume the file path was validated before performing a rename action.

Wayne
0
 
MTEXXCommented:
what about filename collisions, invalid characters, network path access?
always catch those dang exceptions !!
0
 
Wayne Taylor (webtubbs)Commented:
That may be the case, but please show some respect and acknowledge other Experts when you use their solutions.

http://www.experts-exchange.com/help.jsp#hi416

Wayne
0
 
awolarczukAuthor Commented:
Hi Wayne this is my question am i didnt make any bad comments mate i thank everyone for there comments

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.