CopyFile Method

 

Description

 

Copies one or more files from one location to another.

 

PowerBASIC Syntax

 

METHOD CopyFile ( _

BYVAL bstrSource AS STRING, _

BYVAL bstrDestination AS STRING, _

OPTIONAL BYVAL bOverwrite AS INTEGER _

)

 

Arguments

 

bstrSource

BSTR. Character string file specification, which can include wildcard characters, for one or more files to be copied

bstrDestination

BSTR. Character string destination where the file or files from source are to be copied. Wildcard characters are not allowed.

bOverwrite

Boolean value that indicates if existing files are to be overwritten. If true, files are overwritten; if false, they are not. The default is true. Note that CopyFile will fail if destination has the read-only attribute set, regardless of the value of overwrite.

 

Remarks

 

Wildcard characters can only be used in the last path component of the source argument.

 

Example [PowerBASIC]

 

#INCLUDE "windows.inc"

#INCLUDE "scrrun.inc"

 

DIM fso AS IFileSystem

 

' Create an instance of the FileSystemObject

fso = NEWCOM "Scripting.FileSystemObject"

' Copy a file

fso.CopyFile UCODE$("C:\MyFolder\Test.txt"), UCODE$("C:\MyFolder\Test2.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