Link to home
Start Free TrialLog in
Avatar of sdeepu
sdeepu

asked on

how to rename already existing directoryinfo

how to rename already existing directoryinfo ,without deleting it using asp.net codes
kindly please send me answer
ASKER CERTIFIED SOLUTION
Avatar of pratap_r
pratap_r
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kumvjuec
kumvjuec

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");

    }
}