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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Not crafting search phrase right

Status
Not open for further replies.
Oct 10, 2003
90
US
I am sure this question has been asked before.

I have a script, that reads a list of IPs from a text file and performs an action with each IP. Eventually, the script finishes.

I would like to make it a little more inclusive. Read a list of text files, then read the IPs from the first text file, when finished, move to the 2nd text file, etc, etc.

I am working it, but running into minor snags. Probably syntax issues, but looking for the previous posts.
 
Especially if it is syntaxt issues then posting your code is essential.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
I am running into my snag at line 31, wscript.echo lines thrown in so I can see each step finishing





' set scripting environment

set objFSO=createobject("scripting.filesystemobject")

' On Error Resume Next

' at this point, I want to provide the master list of files

master = ("c:\scripts\lists\master.txt")

' define output files
goodPC = ("c:\scripts\output\testing.txt")
badPC = ("c:\scripts\output\testingbad.txt")

set masterlist=objFSo_Opentextfile(master)
set successmachines=objFSO.createtextfile(goodPC)

wscript.Echo goodPC
wscript.Echo badPC

' start first loop, reding first line of master.txt

Do While not masterlist.AtEndOfLine
strFile = masterlist.ReadLine

wscript.Echo strfile

' first file name is passed in, should now be able to run normal text script
' Start looping through the machine names in the file

Do While not strFile.AtEndOfLine

strComputer = strFile.ReadLine

wscript.Echo "should be IP"& strComputer

Loop

loop

'Present yourself a message so you'll know its finsihed

MsgBox "Finished"
 
Here is your code with some revisions. Most of them are just best practice changes (Dimming variables, using Option Explicit, closing textstreams, setting objects to nothing when you are done with them, etc.). Your real problem was that when you read the name of a file from the masterlist, you never opened the file to read from it.
Code:
Option Explicit

Dim objFSO
Dim master
Dim goodPC
Dim badPC
Dim masterlist
Dim successmachines
Dim strFile
Dim oFile
Dim strComputer
Const ForReading = 1
' set scripting environment

set objFSO=createobject("scripting.filesystemobject")

' On Error Resume Next

' at this point, I want to provide the master list of files

master = "c:\scripts\lists\master.txt"

' define output files
goodPC = "c:\scripts\output\testing.txt"
badPC = "c:\scripts\output\testingbad.txt"

set masterlist=objFSO.opentextfile(master, ForReading)
set successmachines=objFSO.createtextfile(goodPC)

wscript.Echo goodPC
wscript.Echo badPC

' start first loop, reding first line of master.txt

Do While not masterlist.AtEndOfLine
    strFile = masterlist.ReadLine
    
    wscript.Echo strFile
    Set oFile = objFSO.OpenTextFile(strFile, ForReading)
    ' first file name is passed in, should now be able to run normal text script
    ' Start looping through the machine names in the file

    Do While Not oFile.AtEndOfLine
        
        strComputer = strFile.ReadLine
        
        wscript.Echo "should be IP"& strComputer
        
    Loop
    oFile.close  
	Set oFile = Nothing
Loop

'Present yourself a message so you'll know its finsihed

masterlist.Close
Set masterlist = Nothing
Set objFSO = Nothing
MsgBox "Finished"

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top