Command Prompt Examples
Using FOR from the command line
Making mammoth tasks easy
Scenario: You have 1500 TIFF image files. Your boss has decided to backup and archive all these files. Instead of zipping up the whole lot to one archive, he wants you to make a zip file for each individual TIFF file.
Task: you need to create 1500 individual zip files, each containing one image. You have two choices:
- One: Do it by hand
- Two: Do it using FOR
To do this you need the free Info-Zip from: http://www.info-zip.org/pub/infozip/Zip.html#Win32. The file you need is: zcr23xN.zip
Then unzip zip.exe from this file into the same folder as the images. For the sake of this example, we’ll use C:\images. Then start a command prompt. START > RUN > CMD (On Windows NT/2K/XP), or START > RUN > COMMAND (On Windows 95/98/ME).
To compress one file (e.g. fred.tiff) we would type:
zip fred.tiff fred
This creates a file called fred.zip in the same folder.
To do this 1500 times, we would type:
for %d IN (*.tiff) DO zip %d %d
This will find all *.tiff files in C:\images and for each one will run zip to zip it up.
 If you use this line in a batch file, you will need to replace %d with %%d.
 It doesn’t have to be %d – you could use any name, such as %file.