Understanding the CompressedFolder Class
(Page 1 of 4 )
In my last series I showed you how to create a custom object class in VBScript that could create compressed files natively. The intent was to demonstrate how to create and use the class rather than to explain the coding concepts. I decided to revisit the topic for a more thorough explanation.
If you haven’t already, you should read my article about Compressed Folders. It will provide a little more insight into the code we’ll be examining today.
First let me explain my theory behind this object class. I wanted an object that would represent a compressed folder (or zip file). Much like the FileSystemObject’s or Shell Object’s Folder objects, I wanted my object to have a series of methods for adding and removing files, along with properties that would describe the file itself. In retrospect, I would have liked to add a size property that would display the compressed folder’s size on disk. Perhaps I’ll put that on my to-do list for the next revision.
Once I had the concept, I made a quick list of the properties and methods that I would like my object to have. This is a good way to get your code class headed in the right direction. By making this list, you are able to organize your thoughts better. You can see how your various properties and methods relate and what outside objects are required, among other things. This can often help in coding the class itself, as you will have a much broader view of the code you’ll need to accomplish each of your tasks. Remember that a code class is more than a script; it’s a small project in and of itself.
Once I had the concept on paper, I was able to determine all of my prerequisites. I knew that I needed the Shell object (along with an ADODB Stream) to create and manipulate compressed folders. In order to implement some error handling, I’d need to check that files exist as well. This is most easily done using the FileSystemObject. It was important to me that I avoided using any objects that weren’t native to the scripting engine. I also wanted to avoid diving into complicated WMI code, so I was off to a very good start.
Next: Examining the Properties >>
More Code Examples Articles
More By Nilpo