• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 717
  • Last Modified:

how to rename already existing directoryinfo

how to rename already existing directoryinfo ,without deleting it using asp.net codes
kindly please send me answer
0
sdeepu
Asked:
sdeepu
1 Solution
 
pratap_rCommented:
Simple..

System.IO.Directory.Move("c:\\dir1","c:\\dir2");

Enjoy!
Pratap

0
 
kumvjuecCommented:
Use the MoveTo memeber function
See the example, Just specify the path of the parent directory of the place where you want it to moveto.

using System;
using System.IO;

public class MoveToTest
{
    public static void Main()
    {

        // Make a reference to a directory.
        DirectoryInfo di = new DirectoryInfo("TempDir");

        // Create the directory only if it does not already exist.
        if (di.Exists == false)
            di.Create();

        // Create a subdirectory in the directory just created.
        DirectoryInfo dis = di.CreateSubdirectory("SubDir");

        // Move the main directory. Note that the contents move with the directory.
        if (Directory.Exists("NewTempDir") == false)
            di.MoveTo("NewTempDir");

    }
}
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now