Iterating on a Set of Files from the Windows Command Line

Album Cover: Icky Thump

"You can't be a pimp and a prostitute, too."
White Stripes / Icky Thump

Posted on May 08, 2008 6:04 PM in Computers
Warning: This blog entry was written two or more years ago. Therefore, it may contain broken links, out-dated or misleading content, or information that is just plain wrong. Please read on with caution.

I'm not a big fan of batch files, most likely because I was exposed to bash scripts well before I ever started to delve into the former. Anyway, I didn't feel like switching to a bash prompt or writing a bash script today when faced with the challenge of iterating on all files of a certain type to perform the same operation on multiple files.

Therefore, I decided I wanted to do something directly from the Windows command line if possible, and shortly thereafter discovered a poorly designed yet inversely informative page on batch file commands that included the following information on the FOR command:

The syntax for this command is: FOR variable in (set list) DO command

The variable must be in the form of one alphabetic character preceeded [sic] by %%; e.g., %%v.

However, if you run the FOR command outside of a batch file, simply from the system prompt, just use a single % in the variable name.

I gave it a shot, and it did what I needed. Here's an example for completion's sake:

FOR %Z IN (*.pl) DO perl %Z

I figured I'd jot it down here at my blog in case the need presents itself in the future (or someone else finds it useful).


itncxfrd on May 15, 2017 at 5:23 AM:

Post Comments

If you feel like commenting on the above item, use the form below. Your email address will be used for personal contact reasons only, and will not be shown on this website.


Email Address:



Check this box if you hate spam.