Friday, November 12, 2010

A Short-cut for Comparisons

Having shown the lowest possible tech version of getting the comparison of files done, I thought I'd show a couple of simple improvements. These (and a few others) can be found in MS_DOS Batch Files, (2nd ed) by Kris Jamsa.


Instead of using dir and then editing the results, we can have DOS do the iteration over files for us. The basic syntax is:

FOR %%I IN (a, b, c) DO command

where command is any DOS command. Specifically, we can use it to call out comparison batch file "comp.bat".

Within the parentheses can be an arbitrary set of files. Wildcards are allowed, so we can write:

compall.bat:

FOR %%I IN (*.f) DO call comp

This one-liner replaces the 60-line file we created with Excel yesterday, and gives identical function.

No comments:

Post a Comment