Copy Method

 

Description

 

Copies a specified file from one location to another.

 

PowerBASIC Syntax

 

METHOD Copy ( _

BYVAL bstrDestination AS STRING, _

BYVAL bOverwrite AS INTEGER _

)

 

Arguments

 

bstrDestination

BSTR. Destination where the file is to be copied. Wildcard characters are not allowed.

bOverwrite

Boolean. Boolean value that is True (default) if existing files are to be overwritten; False if they are not.

 

Remarks

 

The results of the Copy method on a File are identical to operations performed using FileSystemObject.CopyFile where the file referred to by object is passed as an argument. You should note, however, that the alternative methods are capable of copying multiple files.

 

Example [PowerBASIC]

 

#INCLUDE "windows.inc"

#INCLUDE "scrrun.inc"

 

DIM fso AS IFileSystem

DIM pFile AS IFile

 

' Create an instance of the FileSystemObject

fso = NEWCOM "Scripting.FileSystemObject"

' Get a reference to the IFile interface

pFile = fso.GetFile(UCODE$("C:\MyFolder\MyFile.txt"))

' Copy the file

pFile.Copy UCODE$("C:\MyFolder\MyFile2.txt"), %FALSE

IF OBJRESULT = %S_OK THEN

  MSGBOX "File copied"

ELSE

  MSGBOX "Error &H" & HEX$(OBJRESULT) & " copying the file"

END IF

 

Valid XHTML 1.0 Transitional