Batch files: FOR command

by admin on August 14, 2010

For is loop command in Windows.  Using this command we can simplify some of the repetitive tasks. The usage of this command is explained below with examples.

The simplest form of for command is:

for %i in (set) do command command-arguments

Here set means the list of variants for which the command needs to be run.
Example:

You have a list of login names whose accounts need to be deleted from the system. Let’s say the user names are user1, user2, user3, user4, user5, user6. To delete all these user accounts with a single command we can run the below command.

for %i in (user1 user2 user3 user4 user5 user6) do net user /delete %i

If the list of user accounts is stored in a file then we can delete the accounts using the below command.

for /F %i in (filename) do net user /delete %i

{ 0 comments… add one now }

Leave a Comment

Previous post:

Next post: