move a directory in csharp

// tags: c#, move, directory, file management, path

using System.IO;

class Program { static void Main(string[] args) { // Source directory path string sourceDir = @"C:\sourceDirectory";

main.cs
    // Destination directory path
    string destinationDir = @"C:\destinationDirectory";

    // Move the directory and its contents
    Directory.Move(sourceDir, destinationDir);

    // Display success message
    Console.WriteLine("Directory moved successfully.");
}
271 chars
10 lines

}

main.cs

The `Directory.Move` method in C# is used to move the specified directory to a new location. The method takes two parameters: the source directory path and the destination directory path. 

In the code above, we first define the source directory path and the destination directory path. Then, we call the `Directory.Move` method and pass in these paths as arguments. Finally, we display a success message to the console. 

It is important to note that if the destination directory already exists, an exception will be thrown.
527 chars
7 lines

related categories

gistlibby LogSnag