C# Directory Move

Description

Directory Move Moves a file or a directory and its contents to a new location.

Syntax

Directory.Move has the following syntax.


public static void Move(
  string sourceDirName,
  string destDirName
)

Parameters

Directory.Move has the following parameters.

  • sourceDirName - The path of the file or directory to move.
  • destDirName - The path to the new location for sourceDirName. If sourceDirName is a file, then destDirName must also be a file name.

Returns

Directory.Move method returns

Example

The following example demonstrates how to move a directory and all its files to a new directory.


/*from w  ww.  j a v a  2s . c  o m*/

using System;
using System.IO;

class Program
{
    static void Main(string[] args)
    {
        string sourceDirectory = @"C:\source";
        string destinationDirectory = @"C:\destination";
        Directory.Move(sourceDirectory, destinationDirectory);  
    }
}




















Home »
  C# Tutorial »
    System.IO »




BinaryReader
BinaryWriter
Directory
DirectoryInfo
DriveInfo
File
FileInfo
FileStream
MemoryStream
Path
StreamReader
StreamWriter
StringReader
StringWriter