Download a free copy of NetMon - Your Internet Performance Monitor at http://www.codeoftheweek.com/netmon/index.html
In this issue we show to provide a simple backup routine for your applications.
The cBackupFiles class provides a method to backup any file with or without compression. This version of cBackupFiles uses the compression routines that Microsoft supplies free of charge with Visual Basic. It is not an optimal solution since Compress.Exe is a DOS based program, but it is FREE. Next week we will discuss how to restore the compressed files.
If you have any questions about using this class, let us know at firstname.lastname@example.org
Public Sub BackupFile(sSourceFile As String, sDestinationPath As String)
The sSourceFile is the filename that you want to backup. It does not support wildcards at this time. sDestinationPath is the directory to store the file to be backed up. This backup routine will overwrite any existing files. A future issue might show how to check for overwriting destination files.
If no error is raised from this routine it can be assumed that the backup was successful.
Public Property Let CompressionType(eCompType As eCompressionType) Public Property Get CompressionType() As eCompressionType
The CompressionType property allows you to select the type of compression to perform when backing up the files. This class currently supports no compression and Microsoft compression. The eCompressionType values are cmpNone and cmpMicrosoft. You can add your own compression routines by adding a new value to eCompressionType and a new routine to provide the compression for saving the file.
Public Property Get MicrosoftCompressionEXELocation() As String Public Property Let MicrosoftCompressionEXELocation(ByVal sLocation As String)
This routine expects either the path that contains the compress.exe program or a full path and filename of what the compress.exe program is now called. See the comments in the source code for more complete details.
If the file can not be found in the path or filename you have specified it will raise an error.
See each function/property for details.
The below routine can be inserted into your program. It assumes you have installed COMPRESS.EXE into your application directory. It will automatically place any backed up files into a directory called BACKUP under your application directory.
Public Sub BackupFile(sFilename as string) Dim bf As New cBackupFiles On Error GoTo Handler bf.MicrosoftCompressionEXELocation = App.Path & "\compress.exe" bf.CompressionType = cmpMicrosoft bf.BackupFile sFilename, App.Path & "\backup" Exit Sub Handler: MsgBox "An error occurred while trying to backup your file. Msg: " & Err.Number & " " & Err.Description End Sub
To see the source code for this issue you must be a subscriber to Code of the Week. If you are a subscriber the source code is available at the following address: http://www.codeoftheweek.com/membersonly/bi/0083.html