June 1, 2009

Your Very Own ZIP File Creator, Part I

Filed under: Main — admin @ 12:01 am

I warn you: This blog entry is nerdy and technical! It’s not for the beginner!

When I first started writing computer books a century ago, I made a good living writing about DOS batch files. My batch file books were famous. I once got a phone call from a Microsoft employee who kept my batch file book locked in his desk drawer!

Knowing about batch files, and how DOS worked, was important to getting the most from your PC years ago. Here’s a secret: It’s important today as well.

Microsoft has been working on improving the batch file programming abilities in Windows, a little bit with each version. The depth and abilities of batch files in Windows Vista is pretty impressive. To prove it, just type HELP IF at the command prompt to see a slew of improvements to what was once a pretty simple little command.

In my work, I create a lot of ZIP file archives, Compressed Folders that contain the chapters and graphics I send to my publisher. The problem is creating those folders.

You create a Compressed Folder icon in a folder window by right-clicking the window, then choosing New > Compressed (zipped) Folder from the pop-up menu. Doing that over and over to create multiple compressed folders is a pain — and computers are designed to make repetitive tasks easy, right?

The solution I use is to create one Compressed Folder using the above methods. Then I open a Command Prompt window and duplicate the one Compressed Folder several times by using the DOS COPY command. Even that method is contrived.

While duplicating Compressed Folders recently, it dawned on me that there must be a make-zip type of command somewhere in Windows. There isn’t. The only solution Microsoft offers is to write a very long shell script that I found obtuse. That got me to thinking how I could best create a new ZIP file using my old friend the batch file.

A batch file is really nothing more than a collection of DOS commands, all stacked on top of each other, one line at a time, in a text file. The text file is named with the BAT filename extension, which makes it a batch file, an executable file in Windows.

You “run” a batch file by typing its name at the command prompt. The command interpreter then takes each command in the text file, runs it, and moves on to the next command.

There are various programming tools you can use in a batch file, such as IF for decision making and GOTO for branching execution. You can also use variables and such.

In my books, I wrote about augmenting batch files with the DOS DEBUG tool, various helper programs I wrote, and so on. My solution for the create-zip command includes all those tricks, but you’ll have to wait to my next post to read about it and how it works.

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.


Powered by WordPress