Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Rename Directory/Folder

Rename Directory/Folder

Scheduled Pinned Locked Moved C#
question
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    QzRz
    wrote on last edited by
    #1

    Hello I am trying to rename a Direcotry/folder in windows My way to do it goes like this: private void RenameFolder(DirectoryInfo dir, string NewName) { FileInfo fl = new FileInfo(dir.FullName); fl.MoveTo(string.Concat(dir.Parent + "\\" + NewName)); } My question is if this is the best way to rename a directory/folder? Thanks QzRz

    G 1 Reply Last reply
    0
    • Q QzRz

      Hello I am trying to rename a Direcotry/folder in windows My way to do it goes like this: private void RenameFolder(DirectoryInfo dir, string NewName) { FileInfo fl = new FileInfo(dir.FullName); fl.MoveTo(string.Concat(dir.Parent + "\\" + NewName)); } My question is if this is the best way to rename a directory/folder? Thanks QzRz

      G Offline
      G Offline
      Graham Nimbley
      wrote on last edited by
      #2

      Hi. You can also use Directory.Move(string src,string dest) Or even DirectoryInfo.MoveTo() So to use your existing code, this can be simplified to:

      private void RenameFolder(DirectoryInfo dir, string NewName)
      {
      dir.MoveTo(Path.Combine(dir.Parent.FullName,NewName));
      }

      Graham -- modified at 17:12 Sunday 18th June, 2006

      Q 1 Reply Last reply
      0
      • G Graham Nimbley

        Hi. You can also use Directory.Move(string src,string dest) Or even DirectoryInfo.MoveTo() So to use your existing code, this can be simplified to:

        private void RenameFolder(DirectoryInfo dir, string NewName)
        {
        dir.MoveTo(Path.Combine(dir.Parent.FullName,NewName));
        }

        Graham -- modified at 17:12 Sunday 18th June, 2006

        Q Offline
        Q Offline
        QzRz
        wrote on last edited by
        #3

        Hi Thanks for the reply Didnt think of you way to do it, thanks :)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups