Script to create import file

Posted on 2013-05-24
Last Modified: 2013-05-24
I need a script that will read a text file, and for every line in the text file create a few lines of data in a second text file.

input text file looks like this

I need the out put file to look like this

               edit ""
                    set action block
                    set type wildcard
                edit ""
                    set action block
                    set type wildcard
            edit ""
                    set action block
                    set type wildcard
            edit ""
                    set action block
                    set type wildcard
            edit ""
                    set action block
                    set type wildcard
Question by:TheonW
LVL 15

Accepted Solution

ZabagaR earned 500 total points
ID: 39195470
This works, I just tried it:

The variable strFileName will be your final OUTPUT file
The file I called c:\servers.txt would contain the list of your .com web sites.

strFileName = "C:\testfile.txt"
Const ForReading = 1

Set objFS = CreateObject("Scripting.FileSystemObject")
Set MyFile = objFS.CreateTextFile(strFileName, True)
Set objTS = objFS.OpenTextFile(strFileName,FOR_APPENDING)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
    ("c:\servers.txt", ForReading)

Do Until objTextFile.AtEndOfStream
    strNextLine = objTextFile.Readline
    arrServiceList = Split(strNextLine , ",")

objTS.Write "edit " & Chr(34) & arrServiceList(0) & Chr(34) & vbCrLf
objTS.Write "set action block" & vbCrLf
objTS.Write "set type wildcard" & vbCrLf
objTS.Write "next" & vbCrLf


Author Closing Comment

ID: 39195635
I made a few changes for spacing and notice that you put the create file first, no big deal,  easy fix, thanks

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now