Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
YES!!! YES!!! YES!!!
I'm glad to see some one else using FOR, it is a wonderful command and it will save you a LOT of time.
FOR %%[variable] IN (set) DO [command & params]
For will process a command on variable that contains every element in a set, sequentially. I.E. FOR %%C IN (0 1 2 3 4 5 6 7 8 9 A B C D E F) DO ECHO %%C will echo 0 through F, or to the end user it will count from 0 through F in Hex. A couple of notes to keep in mine are: 1) FOR can be used on the command line and in a batch file. On the command line you only need 1 % sign for the variable, where as in a batch file you will need 2 % signs, as DOS reads the % sign as a variable handle. 2) You can only have up to 16 elements in a set as of MS-DOS 6.22. I have not found a limit in the Windows 2000 environment yet. 3) You can not nest FOR loops in MS-DOS 6.22, I have not tested nests in the NT/2k env yet. However you can call %0, the name of the command that was called, i.e. the name of a batch file calling a loop. If you do need to have a nested FOR loop, this is how I recommend that you do it. Below are some examples of how to use the FOR command.
1) Every one has ran a self extracting executable in a directory where they did not want the files to be placed... Dough is in order when this happens. Here's a quick and simple fix for this.
FOR %F IN (*.*) DO DEL ..\%F
This is intended to be ran in a directory that you make and extract the files in for temporary use.

Thanks for that grant.
what i meant to say was
Is anyone aware of a way of running a command using a variable which takes its input from a text file?
i.e.
i have a text file with
namea
nameb
namec
etc
i want to run a command on namea then nameb then namec....etc

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |