Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Problem with FOR loop in Windows 7

Posted on 2014-04-11
2
381 Views
Last Modified: 2014-04-11
I have a very simple text file:
line1
line2
line3

and I am running this plain-vanilla command in a cmd window
FOR /F %i IN (textfile.txt) DO (echo okay)

This should echo the word "okay" three times. Instead it gives me absolutely nothing. Any ideas?
0
Comment
Question by:criskrit
2 Comments
 
LVL 84

Accepted Solution

by:
oBdA earned 500 total points
ID: 39994785
Open the file in Notepad and click "Save as"; somewhere (depending on the version) on the "Save as" page, it'll show the file's encoding. The file is probably saved as Unicode, which can't be interpreted directly by a "for /f" loop.
Either change the encoding to ANSI and save, or use the output of "type" in the loop:
FOR /F %i IN ('type textfile.txt') DO (echo okay)

Open in new window

0
 

Author Comment

by:criskrit
ID: 39994825
#@^&!&@*!(*@&^!@#%*!  --> censored to protect the innocent!

You are a genius!!!!! THANKS!!!!  :-) :-) :-) :-)
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Utilizing an array to gracefully append to a list of EmailAddresses
This Micro Tutorial will teach you the basics of configuring your computer to improve its speed. It will also teach you how to disable programs that are running in the background simultaneously. This will be demonstrated using Windows 7 operating…
This Micro Tutorial will go in depth within Systems and Security in Windows 7 and will go into detail regarding Action Center, Windows Firewall, System, etc. This will be demonstrated using Windows 7 operating system.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question