To rename a directory in C#, you can use the Directory.Move
method. Here's an example:
main.cs123 chars7 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.cs42 chars2 lines
gistlibby LogSnag