rename a directory in csharp

To rename a directory in C#, you can use the Directory.Move method. Here's an example:

main.cs
using System.IO;

string sourceDir = @"C:\sourceDir";
string destDir = @"C:\destDir";

Directory.Move(sourceDir, destDir);
123 chars
7 lines

This code will rename the directory located at C:\sourceDir to C:\destDir.

Note that if the destination directory already exists, this method will throw an exception. If you want to overwrite the destination directory if it exists, you can add a boolean parameter to the method call and set it to true. Like this:

main.cs
Directory.Move(sourceDir, destDir, true);
42 chars
2 lines

gistlibby LogSnag