Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))

Directory.Move Method

Class

System.IO.Directory

Syntax

Directory.Move(sourceDirName, destDirName)

sourceDirName (required; String)

The name of the directory to be moved

destDirName (required; String)

The location to which the source directory and its contents are to be moved

Description

The Move method moves a directory and all its contents, including nested subdirectories and their files, to a new location.

Usage at a Glance

  • sourceDirName and destDirName can be either absolute paths or relative paths from the current directory. destDirName must include the name to be assigned to the moved directory. This allows you to change the directory name as you move it.

  • sourceDirName and destDirName can be either paths on the local system, the paths of a mapped network drive, or UNC paths.

  • Neither sourceDirName nor destDirName can contain wildcard characters.

  • If the directory indicated by destDirName already exists, an error occurs.

Example

The statement:

Directory.Move("c:\folder1", "c:\folder2")

moves folder1 to folder2 in the root of the C drive. That is, it moves all items found within folder1 to a new directory named folder2 and removes the original folder1.

Version Differences

Visual Basic 2005 includes a My.Computer.FileSystem.MoveDirectory method that provides similar functionality.

See Also

Directory.Delete Method

Категории