CopyDirectory Method


CopyDirectory Method

Location

My.Computer.FileSystem.CopyDirectory

Syntax

     My.Computer.FileSystem.CopyDirectory(source, _        destination[, overwrite]) 

or:

     My.Computer.FileSystem.CopyDirectory(source, _    destination, showUI[, onUserCancel]) 


source (required; String)

The path of the directory to be copied.


destination (required; String)

The path of the new directory. New copies of the files contained within source will be stored directly within destination.


overwrite (optional; Boolean)

Indicates whether existing files at the destination should be overwritten (true) or not (False). If this parameter is missing from the first syntax, it defaults to False.


showUI (required in syntax 2; UIOption enumeration)

Indicates whether error or progress dialog windows should appear during the copy. One of the following Microsoft.VisualBasic.FileIO.UIOption enumeration values.

Value

Description

OnlyErrorDialogs

Only shows error dialog boxes; does not display progress

AllDialogs

Shows progress and error dialogs


If this parameter is missing, OnlyErrorDialogs is used by default.


onUserCancel (optional; UICancelOption enumeration)

The progress window includes a Cancel button. When pressed, the method takes action based on this parameter. One of the following Microsoft.VisualBasic.FileIO.UICancelOption enumeration values.

Value

Description

DoNothing

Aborts the copy but returns no information indicating that the copy was cancelled

ThrowException

Throws an exception


If this parameter is missing, THRowException is used by default.

Description

The CopyDirectory method copies the indicated directory and all files within it to a new location. destination is the new final directory; new copies of the files contained within the source directory will appear directly within the destination directory.

Usage at a Glance

  • If the destination directory, though valid, does not exist, it will be created.

  • If a destination directory of the same name already exists, files already found in the destination will be overwritten (when requested) as needed; files without name conflicts will remain. In other words, the source and destination files will be merged.

  • An exception is thrown if the source or destination parameters are missing or invalid.

  • An exception is thrown if the source directory does not exist or a file to be overwritten is in use.

  • An exception is thrown if the user lacks sufficient file access permissions.

  • An exception is thrown if the source and destination are the same or the source contains the destination.

Example

The following example moves a directory to a new parent directory.

     My.Computer.FileSystem.CopyDirectory( _        "C:\Templates\Documents", "C:\Archive") 

Related Framework Entries

  • Microsoft.VisualBasic.FileIO.FileSystem.CopyDirectory Method

  • Microsoft.VisualBasic.MyServices.FileSystemProxy.CopyDirectory Method

See Also

CopyFile Method, CreateDirectory Method, DeleteDirectory Method, DeleteFile Method, FileSystem Object, MoveDirectory Method, MoveFile Method, RenameDirectory Method, RenameFile Method




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net