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";
- try
- {
- Directory.Move(sourceDirName, destDirName);
- }
- catch (IOException exp)
- {
- Console.WriteLine(exp.Message);
- }
Next>>Directories in C#

nop nopPosted Jul 11, 2019, 2:39 PM
Thank you. I have a question. Directory.Move (as DirectoryInfo.MoveTo) fails if the destination directory already exists. Is it possibile move the entire directory, subfolders and files without overwrite existing files as you do with windows gui?I have to move entire directory likesc:\users\username\desktopc:\users\username\favourites to c:\users\NEWusername\desktop c:\users\NEWusername\favourites without overwrite existing files like I do with gui (cut & paste). I have to do as fast as possible to prevent the user from getting scared. Can someone help me, please? Thank you very much
Upendra Pratap ShahiPosted May 22, 2015, 7:42 AM
nice sir..