File Copy With Version Checking

  • xFile – The filename (it copies from the application’s own directory)
  • xDest – The destination directory

Declare

Declare Function GetVersion Lib "Kernel" () As Long
Declare Function GetFileVersionInfo% Lib "VER.DLL" (ByVal lpszFileName$, ByVal handle As Any, ByVal cbBuf&, ByVal lpvData$)

Code

Sub CheckFile(xFile As String, xDest As String)
On Error Resume Next
Dim retS%
Dim retD%
     If Right(xDest, 1) <> "\" Then xDest = xDest + "\"
     Form2.lblSource.Caption = App.Path + "\" + xFile
     Form2.lblDestination.Caption = xDest + xFile
     If Dir(xFile) = "" Then
           FileCopy App.Path + "\" + xFile, xDest + xFile
     Else
           'Check version
           retS% = GetFileVersionInfo(App.Path + "\" + xFile, 0&, 254, version)
           retD% = GetFileVersionInfo(xDest + xFile, 0&, 254, version)
           If retS% >= retD% Then
                 FileCopy App.Path + "\" + xFile, xDest + xFile
           End If
     End If
 
     'Just wait for a sec
     For i = 1 To 1000
           DoEvents
     Next i
 
End Sub

 

Tip Submitted By: Jeff Williams

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s