-4

I have folder and in this folder i have 50 folders. How can i rename,it means, add a letter of folder start,e.g., folder1 => afolder1?

I have tryed already this but it does not work..

DirectoryInfo dir = new DirectoryInfo("C:/Users/Wiz/Desktop/folder/");
foreach (var item in dir.GetDirectories())
{
    Console.WriteLine("a" + item.Name);
}
Console.ReadLine();

After adding soft should save new names in the same directory...

mason
  • 31,774
  • 10
  • 77
  • 121
komra23
  • 107
  • 8
  • 5
    Of course it doesn't work. You didn't write any code to actually change the directory names, just print their current names to the console. Did you expect something different to happen? Did you look at the [MSDN documentation for the Directory class](https://msdn.microsoft.com/en-us/library/system.io.directory.move(v=vs.110).aspx)? – mason Jan 27 '16 at 20:55
  • i have looked there, really,do not lie – komra23 Jan 27 '16 at 21:01
  • Also, remember to look if someone else has asked this same question before or a similar one. Ej: [http://stackoverflow.com/questions/3218910/rename-a-file-in-c-sharp](http://stackoverflow.com/questions/3218910/rename-a-file-in-c-sharp) – Roberto Linares Jan 27 '16 at 21:03
  • 1
    @RobertoLinares That's for renaming a file. [This one](http://stackoverflow.com/questions/2023975/renaming-a-directory-in-c-sharp) is for a directory. – mason Jan 27 '16 at 21:07
  • @mason you're right. Got confused between renaming File and Directory. – Roberto Linares Jan 28 '16 at 16:58

1 Answers1

0

As noted in the comments: you should actually move/rename the folder, not just print out its name.

DirectoryInfo dir = new DirectoryInfo("C:/Users/Wiz/Desktop/folder/");
foreach (var item in dir.GetDirectories())
{
    item.MoveTo(Path.Combine(item.Parent.FullName, "a" + item.Name));
    Console.WriteLine("a" + item.Name);
 }
 Console.ReadLine();
Szabolcs Dézsi
  • 8,743
  • 21
  • 29
  • 1
    It's generally not encouraged to answer a question when so little effort is shown by the asker. – mason Jan 27 '16 at 21:01