Thanks for visiting Daily Cup of Tech!
Here are a few things that you may want to do while you are visiting:

Hope you enjoy your stay!


Command PromptI was doing some tweaks on my new Vista system the other day. One of the things I wanted to so was add a bunch of Visio stencils to my system that I had downloaded from one of the hardware manufacturers. Unfortunately, there were over a hundred stencils and each one was compressed into a ZIP archive. I really didn’t relish right clicking on each zip file, clicking on Extract all…, etc.

So, in situations like this, I immediately drop down to the command prompt. This is where I decided to use the for command to perform and action on every file in the directory.

So, in my example, I used the following command:

for /R %z in (*.zip) do unzip "%z"

Within seconds, I had all of the files extracted and I was ready to go!

Let’s break down this command into its smaller components to see what each one does.

for - indicates that we are going to be using the for command
/R - tells the for command to recursively look in all folders within the active folder as well. Thus, if there are any files in subfolders, they will also be found
%z - this is the variable that will contain the filename that is found. This can be any number but it is case sensitive. If you want to use the for command in a batch file, you will need to use %% (e.g. %%z) instead of just %.
in (*.zip) - this is the search pattern that will be found. The portion in parenthesis uses the same wildcard scheme as the dir command.
do - indicates that the string following is the command that should be executed on each file found
unzip “%z” - this is the actual command that is executed for each file. The %z portion is replaced by the name of the file found. So, for example, if the file found was archive.zip, the command that would be executed would be unzip "archive.zip". Remember that is you are going to be doing this in a batch file, replace the single % with %%.

If you found this post useful, why don't you buy me a cup of coffee to show your gratitude?