Move a directory in C#

The System.IO.Directory class in the .NET Framework class library provides static methods for creating, copying, moving, and deleting directories and subdirectories. Before you can use the Directory class, you must import the System.IO namespace.
  1. using System.IO;  

Move a directory in C#

 
The Directory.Move method moves an existing directory to a new specified directory with full path.  The Move method takes two parameters. The Move method deletes the original directory. 
 
The following code snippet moves the source directory to the destination directory.  
  1. string sourceDirName = @"C:\Temp";  
  2. string destDirName = @"C:\NewTemp";  
  3. try  
  4. {  
  5.     Directory.Move(sourceDirName, destDirName);  
  6. }  
  7. catch (IOException exp)  
  8. {  
  9.     Console.WriteLine(exp.Message);  
  10. }  


Similar Articles
Mindcracker
Founded in 2003, Mindcracker is the authority in custom software development and innovation. We put best practices into action. We deliver solutions based on consumer and industry analysis.