How to change folder or file name using C#? RRS feed

  • Question

  • C#:
          I Making a Project that gets folder and file names in a specific path Location. I have to change (Move) the data from one file to another for some reasons. And also for Folder the files in the specific folder needs to move to another folder [if the new folder doesn't exists then should create a new folder and move them.]

          In Somecases, i needs to change only the Name of the file or folder. How? Is bettter to use the following code..

    //For File:
       System.IO.File.Move(@"C:\old.txt", @"C:\new.txt"); //it renames the file old to new.txt
    //For Folder:
        System.IO.Directory.Move(@"C:\oldfolder", @"C:\newfolder");

    Saturday, September 19, 2009 3:28 PM


All replies