Saturday 29 January 2011

Windows command prompt zip support

I've been writing a script to fetch and build a set of dependencies, and trying to keep it simple. But SDL includes the Visual C project and solution files in a zip file. This is a problem because Windows does not have command line zip file support. The point of this exercise is to just get the job done, not to add other new dependencies.

Something in Windows that jumps out when you have this need, is that there is support for compressed folders. In an Explorer window, you can simply double click on a zip archive and treat it like any other folder. Surely there must be a way to access this functionality from the command line..


My first port of call was Powershell. This comes with later versions of Windows, and shouldn't be an unreasonable dependency - surely it has zip file support? No, this is not the case. But it turns out someone used COM object support to access the shell and work with Explorer.  Unfortunately, this was a false lead.  Powershell lives in its own bubble where scripts need to be signed, to be executed behind the scenes as part of some abstract compilation process.  It isn't acceptable for me to say, go into Powershell and turn off this script security setting that requires signing.  That's worse than adding a dependency, it's a strange incomprehensible complication.  Not doing it gives this lovely error, but it probably gives it to you in equally comprehensible English.


At this point I thought, you know, vbscript never had this problem.  So I searched for "wscript", "zip" and assorted other keywords and came across this script which did exactly the same as the Powershell script, but in straightforward and directly usable vbscript.  Further searching of course was a reminder that all the useful answers are available on the Stack Overflow family of sites, in this case Server Fault.

Problem solved. Of course, nothing comes for free. This is an Explorer action, so copying from a zip folder to another folder, will pop up a file transfer dialog with a progress bar for the duration. However, that is a small price to pay for simplicity.

No comments:

Post a Comment