Computing.Net > Forums > Disk Operating System > Dos Batch commands

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Dos Batch commands

Reply to Message Icon

Name: Emraan
Date: February 2, 2001 at 05:31:44 Pacific
Comment:

Does anyone know how to do a
For

i have a text list of items i would like to apply a command to ?



Sponsored Link
Ads by Google

Response Number 1
Name: DrScriptt (Grant)
Date: February 2, 2001 at 09:07:20 Pacific
Reply:

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.


0

Response Number 2
Name: emraan
Date: February 6, 2001 at 05:52:48 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: Dos Batch commands

Dos Batch command to re-boot a PC. www.computing.net/answers/dos/dos-batch-command-to-reboot-a-pc/3402.html

Dos batch www.computing.net/answers/dos/dos-batch/14574.html

Dos Batch command to terminate a program www.computing.net/answers/dos/dos-batch-command-to-terminate-a-program/3520.html