Visual Basic Code of the Week (COTW)
http://www.codeoftheweek.com
Issue #83
Online Version at http://www.codeoftheweek.com/membersonly/bi/0083.html (paid subscribers only)
All content and source code is Copyright (c) 1999 by C&D Programming Corp. No part of this issue can be reprinted or distributed in any manner without express written permission of C&D Programming Corp. Word, Excel and Visual Basic are trademarks of Microsoft Corp.
Questions? Email us at questions@codeoftheweek.com.

Cool Software

Download a free copy of NetMon - Your Internet Performance Monitor at http://www.codeoftheweek.com/netmon/index.html

In this Issue

In this issue we show to provide a simple backup routine for your applications.

Requirements

cBackupFiles

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 questions@codeoftheweek.com

Methods

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.

Properties

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.

Returns

See each function/property for details.

Sample Usage

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

Source Code

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


This document is available on the web

Paid subscribers can view this issue in HTML format. There is no additional source or information in the HTML formatted document. It just looks a little better since we have included some HTML formatting. Just point your browser to link at the top of this document.

Other links

Contact Information

C&D Programming Corp.
PO Box 20128
Floral Park, NY 11002-0128
Phone or Fax: (212) 504-7945
Email: info@codeoftheweek.com
Web: http://www.codeoftheweek.com