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 firstname.lastname@example.org and let us know. If you are interested in beta testing this library go to the page http://www.codeoftheweek.com/vblibrary.html and fill out the form.
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 email@example.com
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.
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 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/0084.html