Visual Basic Code of the Week (COTW)
Issue #84
Online Version at (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

New Software Tool

We are nearing the release of a new Visual Basic library of routines called VBLibrary that will include all back issues from Code of the Week in a ready-to-use DLL. All source code will be included. If you are interested in this library please contact us at and let us know. If you are interested in beta testing this library go to the page and fill out the form.

In this Issue

In this issue we show to provide a simple restore routine for your applications which builds on the backup routines shown in issue #83.



The cBackupFiles class provides a method to backup and restore 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. This week covers how to restore the files we backed up in last weeks' issue.

If you have any questions about using this class, let us know at


Public Sub RestoreFile(sSourceFile As String, sDestinationPath As String)

The sSourceFile is the filename that you want to restore. It does not support wildcards at this time. sDestinationPath is the directory to store the file to be restored. This restore 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 restore was successful.


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 restore a file backed up with BackupFile and by default places the file into your application directory.

Public Sub RestoreFile(sFilename as string)
    Dim bf As New cBackupFiles

    On Error GoTo Handler
    bf.MicrosoftCompressionEXELocation = App.Path & "\compress.exe"
    bf.CompressionType = cmpMicrosoft
    bf.RestoreFile sFilename,  App.Path
    Exit Sub

    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:

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