• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 406
  • Last Modified:

Problem with FOR loop in Windows 7

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
criskrit
Asked:
criskrit
1 Solution
 
oBdACommented:
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
 
criskritAuthor Commented:
#@^&!&@*!(*@&^!@#%*!  --> censored to protect the innocent!

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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now