Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bad File Mode 2

Status
Not open for further replies.

Keyster86

IS-IT--Management
Jul 23, 2008
50
US
I must be half asleep - I can't for the life of me figure out why the code is throwing an error. Please help.

Code:
SET objFSO = CreateObject("Scripting.fileSystemObject")
SET objFileTEXT = objFSO.OpenTextFile("hosts.txt",2,TRUE)

DO UNTIL objFileTEXT.AtEndOfStream
	strComputer = objFileTEXT.ReadLine
	wscript.echo strComputer
LOOP

V/r,

SPC Key
United States Army
 
>SET objFileTEXT = objFSO.OpenTextFile("hosts.txt",2,TRUE)
[tt]SET objFileTEXT = objFSO.OpenTextFile("hosts.txt",[red]1[/red],TRUE)[/tt]

If you attempt to read the file, it is 1 (for reading) not 2 (for writing only).
 
Keyster86:
I would get in the habit of using constants; add this to the top of every script that uses FSO for input/output:

Const ForReading = 1, ForWriting = 2, ForAppending = 8

SET objFileTEXT = objFSO.OpenTextFile("hosts.txt",ForReading,TRUE)

Makes the code much more readable for yourself, or the next programmer who would have to maintain your code.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top