Mono Class Library: System.IO.Directory Overview | Members

System.IO.Directory.Move Method

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

public static void Move (string sourceDirName, string destDirName)

Parameters

sourceDirName
A string containing the name of the file or directory to move.
destDirName
A string containing the new location for sourceDirName. This string cannot identify an existing file or directory.

Permissions

TypeReason
System.Security.Permissions.FileIOPermissionRequires permission to read from sourceDirName, and write to sourceDirName and destDirName. See System.Security.Permissions.FileIOPermissionAccess.Read, System.Security.Permissions.FileIOPermissionAccess.Write.

Exceptions

TypeReason
ArgumentExceptionsourceDirName or destDirName is a zero-length string, contains only white space, or contains implementation-specific invalid characters.
ArgumentNullExceptionsourceDirName or destDirName is null.
System.Security.SecurityExceptionThe caller does not have the required permission.
System.IO.IOException

An attempt was made to move a directory to a different volume,

-or-

destDirName already exists.

-or-

sourceDirName and destDirName refer to the same file or directory.

System.IO.DirectoryNotFoundExceptionsourceDirName was not found.
System.IO.PathTooLongExceptionThe length or absolute path information for sourceDirName or destDirName exceeds the system-defined maximum length.
UnauthorizedAccessExceptionThe caller does not have the required permission.

Remarks

The destDirName argument cannot specify a location on a different disk or volume than sourceDirName. The sourceDirName and destDirName arguments cannot identify the same file or directory.

Note: This method throws a System.IO.IOException if, for example, you try to move "\mydir" to "\public", and "\public" already exists. You must specify "\public\mydir" as the destDirName.

The sourceDirName and destDirName arguments are permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory.

Note: To obtain the current working directory, see Directory.GetCurrentDirectory.

Requirements

Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0