Visual Basic 6 function "copy"

Go back

Below you'll find the source for the Visual Basic 6 function copy.

Attribute VB_Name = "modCopy"
' These functions are downloaded from:
' You may freely distribute this file but please leave all comments, including this one, in it.
' @Author Stefan Thoolen <>

Option Explicit

' This function checks if a file exists and returns true or false
' Same syntax as the PHP function 'file_exists'
' See also:
' @param    String  filename        The file to check for
' @return   Boolean                 Wether the file exist or not
' @author   Stefan Thoolen <>
Public Function file_exists(filename) As Boolean
    If Dir(filename, vbHidden Or vbReadOnly Or vbSystem Or vbArchive) <> "" Then file_exists = true
End Function

' This function copies a file
' Same syntax as the PHP function 'copy' except for the context-parameter
' See also:
' Dependency: Scripting.FileSystemObject (.NET Framework 2.0)
' @param    String  source      The source filename
' @param    String  dest        The destination filename
' @return   Boolean             True on success, false otherwise
' @author   Stefan Thoolen <>
Public Function copy(source As String, dest As String) As Boolean
    On Error GoTo copy_error
    If Not file_exists(source) Then Exit Function
    Dim fso As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    fso.copyfile source, dest, True
    copy = file_exists(dest)
    On Error Goto 0
    Set fso = Nothing
    Exit Function
    copy = False
    Resume copy_end
End Function