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

Loop VBScripts many times by the use of text or csv file

Status
Not open for further replies.

heimly

Technical User
Jul 22, 2010
5
NO
I have made one script that i must run on many different sites in an aplication
Is it possible to run it at once depend of text file ore csv file.
I am new on this. I have try following:

Set FSO=CreateObject("Scripting.FileSystemObject")
Set TF2=FSO.OpenTextFile("D:\temp\all.txt",1) ' 1=ForReading
Do
line=TF2.ReadLine
Set TF=FSO.OpenTextFile(line,1) ' 1=ForReading2
inp=TF.ReadAll
out1=Replace(inp,"Find","Replace")
out2=Replace(out1,"Find","Replace")
out3=Replace(out2,"Find","Replace")
out4=Replace(out3,"Find","Replace")
out5=Replace(out4,"Find","Replace")
TF.close
Set TF=FSO.CreateTextFile(line,True)
TF.Writeline out5
TF.Close
While line<>""

TF2.Close

I hav on error
(36, 10) Microsoft VBScript compilation error: Expected 'Wend'

Exit code: 1, 0001h
Line 36 is the last line

Thanks Erik
 
I'm no scripting expert, but I believe your loop is incorrect. Try the following:

Code:
Set FSO=CreateObject("Scripting.FileSystemObject")
Set TF2=FSO.OpenTextFile("D:\temp\all.txt",1) ' 1=ForReading
Do while not TF2.atendofstream
    line=TF2.ReadLine
    Set TF=FSO.OpenTextFile(line,1) ' 1=ForReading2
    inp=TF.ReadAll
    out1=Replace(inp,"Find","Replace")
    out2=Replace(out1,"Find","Replace")
    out3=Replace(out2,"Find","Replace")
    out4=Replace(out3,"Find","Replace")
    out5=Replace(out4,"Find","Replace")
    TF.close
    Set TF=FSO.CreateTextFile(line,True)
    TF.Writeline out5
    TF.Close
loop

TF2.Close
 
I explain how to do this and a lot more in my FAQ:

I hope that helps.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top