Compressed Folders in WSH
(Page 1 of 4 )
Windows XP provides built-in zip file support in a feature referred to as Compressed Folders. While the compression of a Compressed Folder is not as effective as many third-party implementations, it does offer great compatibility since it is natively supported on all modern Windows platforms.
For whatever reason, Microsoft did not include any scripting support for creating Compressed Folders. There isn’t any viable command line for creating them either. So that’s that; we shed our tears and walk away.
But then again, that wouldn’t make for a very interesting article, and there’s a good chance my editors might have something to say about it when it comes time to pay me. So I guess we’ll have to make a workaround.
Compressed folders are implemented as a Windows Shell extension. They are available in the context menu from within Windows Explorer. Typically we would start looking here for a workaround, since we can often execute context menu items using the InvokeVerb method of the Windows Shell’s scripting interface. However, the Compressed Folder item appears in the New menu and we don’t have access to that.
That pretty much exhausts every avenue of automating the feature itself. Let’s take a look at creating the file directly. To do that you’ll need a hex editor like XVI32. A hex editor allows you to open and view binary files like the Compress Folders in which we’re so interested.
If you were to create a Compressed Folder in Windows Explorer, you would notice that it is nothing more than a .zip file. If we open that empty .zip file in a hex editor, we may be able to see its binary composition and duplicate it to create our own zip files.
As it turns out, Compressed Folders are actually very basic binary files that consist of a series of twenty-two bytes as follows:
50 4B 05 06 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Each two-digit pair represents a single byte. This number is a hex value that represents some character. For example, 50 in hex equals 80 in decimal. The ASCII code for character 80 is the capital letter P. I’m going to spare myself the lengthy explanation here since we’re going to be working with the values that we see here. Essentially, this file has the letters PK followed by a series of non-printable characters.
Next: Creating a Binary file >>
More Windows Scripting Articles
More By Nilpo