Location My.Computer.FileSystem.CopyFile Syntax My.Computer.FileSystem.CopyFile(source, destination[, overwrite]) or: My.Computer.FileSystem.CopyFile(source, destination, _ showUI[, onUserCancel])
source (required; String) The path of the file to be copied.
destination (required; String) The path of the new destination file.
overwrite (optional; Boolean) Indicates whether an existing file 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 CopyFile method copies the indicated file to a new location. Usage at a Glance If the destination directory, though valid, does not exist, it will be created. An exception is thrown if the source or destination parameters are missing or invalid. An exception is thrown if the source file does not exist or is in use, or if a file to be overwritten is in use. An exception is thrown if the user lacks sufficient file access permissions. Example The following example copies a file to a new location, overwriting any existing file with the same name. My.Computer.FileSystem.CopyFile( _ "C:\Templates\project.txt", "C:\NewProject\project.txt", True) Related Framework Entries Microsoft.VisualBasic.FileIO.FileSystem.CopyFile Method Microsoft.VisualBasic.MyServices.FileSystemProxy.CopyFile Method System.IO.File.Copy Method See Also CopyDirectory Method, CreateDirectory Method, DeleteDirectory Method, DeleteFile Method, FileSystem Object, MoveDirectory Method, MoveFile Method, RenameDirectory Method, RenameFile Method |