Renaming files

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John

    Renaming files

    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


  • Dale Levesque

    #2
    Re: Renaming files

    My.Computer.Fil esystem.RenameF ile


    or

    ' How to move / rename a file.
    Private Sub button6_Click(s ender As Object, e As System.EventArg s)

    Dim fi As New FileInfo("myIma ge.gif")

    fi.MoveTo("myIm age2.gif")

    End Sub 'button6_Click




    "John" <info@nospam.in fovis.co.ukwrot e in message
    news:u966$1hjIH A.2396@TK2MSFTN GP05.phx.gbl...
    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
    >

    Comment

    • kimiraikkonen

      #3
      Re: Renaming files

      On Mar 25, 4:11 am, "John" <i...@nospam.in fovis.co.ukwrot e:
      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.FileI nfo("c:\test.tx t")

      ' 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.

      Comment

      • Herfried K. Wagner [MVP]

        #4
        Re: Renaming files

        "John" <info@nospam.in fovis.co.ukschr ieb:
        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.Fi leSystem.Rename File'
        'My.Computer.Fi leSystem.Rename Directory'
        'File.Move'
        'Directory.Move '

        --
        M S Herfried K. Wagner
        M V P <URL:http://dotnet.mvps.org/>
        V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

        Comment

        Working...