Reader Level:

Move a directory in C#

By Mahesh Chand on Jul 17, 2012
How to move a directory using C# and .NET.

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. 
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.  

string sourceDirName = @"C:\Temp";
string destDirName = @"C:\NewTemp";
    Directory.Move(sourceDirName, destDirName);
catch (IOException exp)

Download free book: Working with Directories in C#

Mahesh Chand
Mahesh Chand

C# Corner founder, 10-times Microsoft MVP, technical author, and software architect. Mahesh authored his first book, A Programmer’s Guide to ADO.NET in C# with APress at the age of 25. C# Corner is a memb... Read more



Custom Software Development
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.

Trending up