#Use zip files code#
GoToSleep is a bit of code that uses the Sleep API to pause execution for the number of milliseconds specified and then continue execution, (shown in Sample 3). You may be wondering about the reference to GoToSleep in that code. If you try to use a string variable instead, you'll end up getting an error 91 ("Object variable or With block variable not set")
#Use zip files zip file#
The reason for introducing varZipFIle into that code is that, for reasons I haven't bothered to determine, the name of the zip file must be stored in a variant in order to use it as the NameSpace. Sample 2 – The code required to add a single file to a new Zip file ObjShell.NameSpace(varZipFile).Items.Count _
ObjShell.NameSpace(varZipFile).CopyHere _ Once you've created the Folder object, you use its CopyHere method to add the file to the Zip file.
You then instantiate an instance of the Shell application and use the NameSpace method of the Shell object to create a Folder object. To create a Zip file and add a file to it, then, requires that you initialize the Zip file as shown. It then uses the Open statement to enable output to the file (thereby creating the file), and the Print statement to write the twenty-two byte signature to it. The code first checks whether the file already exists, and deletes it if it does. Sample 1 – The code required to mark an empty file as a Zip file The code required to designate a new file as a Zip file, then, is presented as Sample 1. These twenty-two bytes consist of the following ASCII characters: Chr$(80) & Chr$(75) & Chr$(5) & Chr$(6) & String(18, 0).
#Use zip files windows#
It turns out that what causes the Windows Shell to treat a Zip file as a folder, is the presence of a specific twenty-two byte "fingerprint" at the very beginning of the file. Hopefully, like me, you're willing to accept this as magic! ZIP File Format Specification ( ) and I have to confess that it didn't help me understand how the method I'm about to demonstrate works. Since to Windows Shell, it's simply a folder, you can use the NameSpace method of the Shell object to create a Folder object that points to the contents of Zip file, just as it's possible to point to the contents of any other folder.
In fact, as Figure 1 illustrates, when you right-click on a file and select Send To, Windows Shell actually presents the option of zipping the file as "Compressed (zipped) Folder"įigure 1: The Send To menu - Windows Shell gives a choice of "Compressed (zipped) Folder" To Windows, a Zip file really is not different from a folder, since it can contains multiple files. To some extent, referring to a "Zip file" is incorrect: from the perspective of the Windows Shell object. The ZIP file format permits a number of different compression algorithms to be used, with the dominant method (and the one used by Windows) being the Deflate method. If you want more information about the Shell, start at what's in MSDN at (VS.85).aspx What is a Zip file?Ī ZIP file contains one or more files that have been compressed to reduce file size (although the file format also allows files to be stored "as-is"). You're presumably familiar with the commands you can access from the Start menu and the taskbar's shortcut menu: all that functionality is exposed through the Shell object.Īs you can well imagine, the Windows Shell is a large and complicated topic, and I'm only going to be discussing one small part of it.