FileCopy (statement)

Syntax

FileCopy source$, destination$

Description

Copies a source$ file to a destination$ file.

Comments

The FileCopy function takes the following parameters:

 

Parameter

Description

 

source$

String containing the name of a single file to copy.

The source$ parameter cannot contain wildcards (? or *) but may contain path information.

 

destination$

String containing a single, unique destination file, which may contain a drive and path specification.

 

The file will be copied and renamed if the source$ and destination$ filenames are not the same.

Some platforms do not support drive letters and may not support dots to indicate current and parent directories.

Example

This example copies the autoexec.bat file to "autoexec.sav", then opens the copied file and tries to copy it again--which generates an error.

Sub Main()
  On Error Goto ErrHandler
  FileCopy "c:\autoexec.bat","c:\autoexec.sav"
  Open "c:\autoexec.sav" For Input As # 1
  FileCopy "c:\autoexec.sav","c:\autoexec.sv2"
  Close
  Exit Sub

ErrHandler:
  If Err = 55 Then       'File already open.
    MsgBox "Cannot copy an open file. Close it and try again."
  Else
    MsgBox "An unspecified file copy error has occurred."
  End If
  Resume Next
End Sub

See Also

Kill (statement); Name (statement).

More information

F