eHow launches Android app: Get the best of eHow on the go.

How To

How to use a for loop in a batch file

Member
By Todd Bearrows
User-Submitted Article
(1 Ratings)

If you ever had a list of files or directories that you wanted to feed in to a batch file this is how you can do it. It's really simple for any one that has worked with Dos before.

Difficulty: Moderate
Instructions

Things You'll Need:

  • Windows pc
  1. Step 1

    Open notepad

  2. Step 2

    Copy this text to notepad

    FOR /F "tokens=1" %%A IN (C:\bin\todolist.txt) DO (copy %%A "\\backup\folder" )

  3. Step 3

    Replace "c:\bin\todolist.txt" with the path to the text file that you want the batch file to read from.

  4. Step 4

    Replace "copy" with the command you want to run. \\backup\folder is the destination folder I'm coping to so delete that depending on your command.

  5. Step 5

    Save your file as whatever.bat.

Tips & Warnings
  • Note the 2 % signs. You need to use two in batch files
  • You can add more tokens up to 52
Subscribe

Post a Comment

Post a Comment

Related Ads

  • Have you done this? Click here to let us know.
I Did This
Get Free Computers Newsletters

Copyright © 1999-2009 eHow, Inc. Use of this web site constitutes acceptance of the eHow Terms of Use and Privacy Policy .   en-US Portions of this page are modifications based on work created and shared by Google and used according to terms described in the Creative Commons 3.0 Attribution License. † requires javascript

eHow Computers
eHow_eHow Technology and Electronics