PBDR.COM

About   -   Contact   -   Purchase   -   Search   -   What's New

 
 
CopyFile Function
This function is used in conjunction with the CopyTree function and is an extension of the standard FileCopy function. The extra code is added to trap possible file attribute problems. Add the following code to a FileHandling.bas standard module to compile a File Utility function set:
Public Function CopyFile(srcefile As String, destfile As String, _
  errnum As Integer) As Boolean
'*****************************************************************
'<DESC>		Copies individual files to new location.</DESC>
'<RETURN>		Boolean:
'			Success level of function</RETURN>
'<ACCESS>		Public</ACCESS>
'<ARGS>		srcefile: 
'			Full Filepath & Filename of source
'   		destfile: 
'			Full Filepath & Filename of destination
'		</ARGS>
'<USAGE>		blnCopy = CopyFile("c:\autoexec.bat", _    
'			  "c:\temp\autoexec.old", 0)</USAGE>
'*****************************************************************

Dim intAttr As Integer
    
    DoEvents
    CopyFile = False
    
    On Error Resume Next
    
    Err = 0
    FileCopy srcefile, destfile
    
    Select Case Err
        Case 0                  ' OK
            CopyFile = True
        Case 75                 ' Path/File Access error
            intAttr = GetAttr(destfile)
            SetAttr destfile, vbNormal
            Err = 0
            FileCopy srcefile, destfile
            If Err = 0 Then
                intAttr = intAttr Or vbArchive
                SetAttr destfile, intAttr
                CopyFile = True
            Else
                errnum = Err
            End If
        Case Else               ' Other error
            errnum = Err
    End Select

End Function
 

Top of Page

Legal Notice

Ken Howe 2011