Let's jump straight into a command-line example of how to use FOR:
E:\>for %x in (one two three) do echo %x E:\>echo one one E:\>echo two two E:\>echo three threeAs you can see, the FOR command caused echo to be executed three times -- once for each word in it's "set" of arguments. If we were able to replace the "set" with an entire data line, we could do some real processing without the crazy antics other methods need. Obviously, we'll have to replace the echo command with something a bit more useful, but you already figured that out. Now, the only reasonable way I can see to get an entire data line into the middle of our FOR line is to put that line in the environment. So we'll go to the next example, this one a batch file assuming the prior existence of an environment variable named "DATALINE":
@echo off echo echo %%1> process.bat for %%x in (%dataline%) do call process.bat %%x del process.batAssuming our environment variable DATALINE contains the same one two three text, the example above would generate this output:
Now lets discuss file masks and the LFNFOR command.
C:\Temp>dir Volume in drive C is WINDOWS95 Volume Serial Number is 1251-1BED Directory of C:\Temp . <DIR> 04-14-97 8:23a . .. <DIR> 04-14-97 8:23a .. LONGFI~1 TXT 16 06-12-98 8:52a long file name.txt 1 file(s) 16 bytes 2 dir(s) 55,918,592 bytes free
C:\Temp>lfnfor on C:\Temp>for %x in (*.*) do echo %x C:\Temp>echo long file name.txt long file name.txt
C:\Temp>lfnfor off C:\Temp>for %x in (*.*) do echo %x C:\Temp>echo LONGFI~1.TXT LONGFI~1.TXTSo let's put it all together. Suppose you want to print out all your basic and batch files. Notepad can do this under batch control with the /p option. But it prints out the title at the top of each page, and it will print the long or short name depending on how it opened the file. So this line in a batch file:
Lost? Look at the site map.
Bad links? Questions? Send me mail.