UtterAccess HomeUtterAccess Wiki

Welcome Guest ( Log In | Register )

Custom Search
Edit Discussion
> VerifyFile    

The VerifyFile function was created with the intent to verify a critical file copy operation before performing work/deletions on the original. It checks that the file exists in a specific location, and that the file size in bytes is a specific number.

Example Usage as a FileCopy verification:

CODE

FileCopy SourceFile, DestFile
If Not VerifyFile(DestFile, FileLen(SourceFile)) Then
 Err.Raise vbObjectError, , "The FileCopy performed a corrupt or aborted copy!"
End If
The following code performs the two verification checks and requires no dependancies other than VBA. The approximate maximum filesize that can be verified with this function is 2gb.
CODE

Public Function VerifyFile(sPath As String, lBytes As Long) As Boolean
 ' VerifyFile
 ' http://www.utteraccess.com/wiki/index.php/VerifyFile
 ' Code courtesy of UtterAccess Wiki
 ' Licensed under Creative Commons License
 ' http://creativecommons.org/licenses/by-sa/3.0/
 '
 ' You are free to use this code in any application,
 ' provided this notice is left unchanged.  
 '
 ' rev  date                          brief descripton
 ' 1.0  2011-08-04                    
 '

 'make sure it exists
 If Len(Nz(Dir(sPath))) = 0 Then
   VerifyFile = False
 Else
   'check size in bytes
   If FileLen(sPath) <> lBytes Then
     VerifyFile = False
   Else
     VerifyFile = True
   End If
 End If

End Function


Creative Commons License
VerifyFile by UtterAccess Wiki is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Editing and revision of the content is freely encouraged; for details, see Expected Usage.

Edit Discussion
Custom Search
Thank you for your support!
This page has been accessed 3,046 times.  This page was last modified 01:01, 5 August 2011 by Jack Leach.   Disclaimers