Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
Hi guys,
 
I want to rename folders and sub folder in UNC path.
 

I tried a lot but,I am not able find the solution,
 

Note: I don't want Create folders/Move the existing folder using
 
System.IO.Directory.Move
 
Existing folder need to change the folder name.

 

Any help will be appreciated
 

 
Thanks and regards
 
Vishwa
Posted 15-Jan-13 0:48am
Edited 15-Jan-13 16:08pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Remember you can only rename the folder, if you have the access rights.
"movie" is the name of the folder and exist in D drive and is renamed to movies or anything you desire.
 
try the below code
System.IO.Directory.Move(@"D:\movie", @"D:\movies");
 
For more info, visit MSDN[^]
  Permalink  
v2
Comments
VishwaKL at 15-Jan-13 6:06am
   
I want to rename locally
 
Ex if my folder is C:\ABC_A\ABC
 
i want to make it C:\ABCA\ABC
 
like how we rename in windows
Shanu2rick at 15-Jan-13 6:12am
   
Exactly it will rename ABC_A to ABCA using the Move() method.
Like this
System.IO.Directory.Move(@"C:\ABC_A", @"C:\ABCA");
Just try it you'll see the result by yourself.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Use the Directory.Move[^] method.
  Permalink  
Comments
VishwaKL at 15-Jan-13 20:59pm
   
I don't want to move the folder, in locally i have to change the folder name , like how we do in Windows xp, right click change folder name
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

How to rename a directory or folder in C#[^]
 
OR see this example-
 
using System;
using System.IO;
 
namespace Folder
{
    class Program
    {
        static void Main(string[] args)
        {
            string sourceDirectory = @"C:\sourcelocation";
            string destinationDirectory = @"C:\destinationlocation";
 
            try
            {
                Directory.Move(sourceDirectory, destinationDirectory);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
    }
}
  Permalink  
Comments
VishwaKL at 15-Jan-13 21:00pm
   
I don't want to move the folder, in locally i have to change the folder name , like how we do in Windows xp, right click change folder name
Abhishek Pant at 16-Jan-13 2:04am
   
Also,OriginalGriff expained below in the comments.
Abhishek Pant at 15-Jan-13 21:27pm
   
I didn't said to move it I said to rename it with new name at destinationlocation
OriginalGriff at 16-Jan-13 1:59am
   
I know.
The Move method renames directories of the rest of the path is the same:
Directory.Move(@"C:\Temp\oldFolderName", @"C:\Temp\newFolderName");
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Please check the below links to find how to rename folders and sub folders.
1. changing the name of folders with subfolders that also require name changes..[^].
2. SVN – Sub-Directory Renames via C#[^].
 
Thanks...
Comments
VishwaKL at 15-Jan-13 21:00pm
   
I don't want to move the folder, in locally i have to change the folder name , like how we do in Windows xp, right click change folder name
Tadit Dash at 16-Jan-13 1:38am
   
The solution provided in these links don't move the folders, instead it just renames. That is what you wanted.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

Looped through and used same move method to rename
 
Thanks For the support
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 7

protected void Page_Load(object sender, EventArgs e)
        {
            folder("newfoler");
        }
        public void folder(string name)
        {
            bool exists = System.IO.Directory.Exists(Server.MapPath(name));
 
            if (!exists)
                System.IO.Directory.CreateDirectory(Server.MapPath(name));
            else
            {
                string previousname = Server.MapPath(name);
                string newname=Server.MapPath(name + "120");
                Directory.Move(previousname,newname );
            }
        }
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 450
1 OriginalGriff 180
2 DamithSL 130
3 Dave Kreskowiak 120
4 Suvendu Shekhar Giri 110
0 OriginalGriff 7,645
1 DamithSL 5,614
2 Sergey Alexandrovich Kryukov 5,344
3 Maciej Los 4,961
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web02 | 2.8.141223.1 | Last Updated 11 Nov 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100